Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #2192 (closed defect: fixed)

Opened 10 years ago

Last modified 9 years ago

Mako template loader for non-dotted template names fail to init

Reported by: kikidonk Owned by: faide
Priority: normal Milestone: 2.1b1
Component: Documentation Version: trunk
Severity: normal Keywords:
Cc:

Description

Mako's TemplateLookup? expect module_directory parameter to be a single item but: http://trac.turbogears.org/browser/trunk/tg/configuration.py#L313 passes the list of templates directories from self.paths resulting in an exception being raised.

The module_directory argument is a single directory where all generated-modules will be created when a template is compiled by mako.

  • A simple fix is to use self.pathstemplates?[0] but it might break in some weird ways when there are multiple templates directories
  • Even then, this value should be configurable, because the webserver might not have write-access to the templates directory created by the egg-file once deployed
  • Also note that when running setup.py bdist_egg if there are any compiled templates hanging aroung in templates/ they will be included in the egg file which might not be desirable

Note: you have to use use_dotted_templatenames = False in your config to hit this bug.

Change History

comment:1 Changed 10 years ago by faide

  • Status changed from new to assigned

I know I may be asking a bit too much but you seem to be involved in tg dev quite a bit so I try :)

Could you write a tg test that exhibits this problem? This is located in:

tg/test_stack/rendering/test_rendering.py

Florent.

comment:2 Changed 10 years ago by faide

I don't have a clear idea on the solution we need to apply here. Need to think a bit...

comment:3 Changed 10 years ago by faide

Would a single "compiled_dir" be sufficient or would it fail if there are more than one template directory?

comment:4 Changed 10 years ago by kikidonk

This is because the test config doesn't match the standard config. Compare this:

Index: tg/test_stack/__init__.py
===================================================================
--- tg/test_stack/__init__.py	(revision 6276)
+++ tg/test_stack/__init__.py	(working copy)
@@ -29,7 +29,7 @@
                     root=test_base_path,
                     controllers=os.path.join(test_config_path, 'controllers'),
                     static_files=os.path.join(test_config_path, 'public'),
-                    templates=os.path.join(test_config_path, 'templates')
+                    templates=[os.path.join(test_config_path, 'templates')]
                     )
         print self.package

with this http://trac.turbogears.org/browser/trunk/tg/configuration.py?rev=6276#L174

where the self.paths is setup. In configuration.py for some reasons a list is created for template paths

comment:5 Changed 10 years ago by kikidonk

According to the doc there can be multiple template dirs (this is what 'directories' is for), and one single compiled template directory (module_directory).

I guess the fix is to still use directories=self.paths['templates'] but to use module_dir=self.paths['compiled_templates'] which must return a single directory that is writable by the webserver

comment:6 Changed 10 years ago by faide

we will need a new deployment config option to indicate a directory where the web server has write access to put the compiled templates. What about:

templating.mako.compiled_templates_dir = somedir

in the app:main section of the .ini files. If no option is found the server will try to specify the first template dir as the compile dir so that development install do no have to bother about setting this option manually.

what do you think?

comment:7 Changed 10 years ago by kikidonk

That sounds fine !

comment:8 Changed 10 years ago by faide

Added the option in r6329 of tg.devtools so that the default development.ini templates give indication of the existence of this option.

comment:9 Changed 10 years ago by faide

  • Component changed from TurboGears to Documentation

putting this ticket in the documentation component so that it can be found during next Doc sprint...

comment:10 Changed 10 years ago by mramm

  • Milestone changed from 2.0b6 to 2.0 RC 1

comment:11 Changed 10 years ago by mramm

  • Milestone changed from 2.0rc1 to 2.0rc2

comment:12 Changed 10 years ago by percious

  • Milestone changed from 2.1a1 to 2.1 docs

comment:13 Changed 10 years ago by seedifferently

I would like to reiterate (as the OP stated) that this functionality is broken unless you set use_dotted_templatenames to False. This is very disappointing. Please see #2395 for further info.

comment:14 Changed 9 years ago by percious

  • Milestone changed from 2.1 docs to 2.1a3

comment:15 Changed 9 years ago by percious

  • Status changed from assigned to closed
  • Resolution set to fixed
Note: See TracTickets for help on using tickets.