Cannot use Mako templates not ending in '.html'

Bug #252232 reported by Alex Hirzel
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
web.py
Confirmed
Low
Anand Chitipothu

Bug Description

When using web.contrib.template.render_mako, you cannot use templates which have anything other than '.html' for an extension.

In my specific application, I need to use templates which have no extension in their filename.

Ideally, a feature such as "assume .html extension" would exist in Mako proper (as a filename_extension option on the TemplateLookup constructor, perhaps,) so that inheritance would also assume the default extension (so you don't have to use "overview" within web.py but "overview.html" within the template files themselves.) I plan to throw this idea at the Mako team.

If the above feature is integrated into Mako, the _extension option should still exist within web.py so that when a user opts to specify the filename extension in every invocation (i.e. call TemplateLookup with filename_extension='' but still have 'overview.html',) then web.py won't be getting confused by calls to render.overview.html (fails to getattr) rather than render.overview.

I have attached a patch against an April 2008 devel version which adds an _extension option to the render_mako constructor, as well as a self-explanatory example in the docstring.

Revision history for this message
Alex Hirzel (alexander-hirzel) wrote :
Revision history for this message
Anand Chitipothu (anandology) wrote : Re: [Bug 252232] Re: Cannot use Mako templates not ending in '.html'

What if there are templates with different extensions?

Revision history for this message
Alex Hirzel (alexander-hirzel) wrote :

I cannot think of a trivial way to implement that one.

Maybe an alternative approach is in order: infer the extension from the filesystem, i.e. render.hello() will actually call hello.html if present, and in the same Python source file, render.goodbye() would call upon goodbye.txt or something. This would require detecting the file on the filesystem, however, and it would also require a sensible way to resolve ambiguous cases. The specifics would obviously be up to whoever implements it. Such a feature should probably be in Mako proper.

Changed in webpy:
assignee: nobody → anandology
importance: Undecided → Low
milestone: none → 0.3
status: New → Confirmed
Changed in webpy:
milestone: 0.3 → 0.35
Revision history for this message
foxbunny (bg-branko) wrote :

This patch allows one to use a template with any extension the way Templetor does.

However, I think the part where filename is looked up using glob (also present in Templetor code and another patch I submitted for Evoque template) should be extracted and put into web.utils, so all template backends can use the same code. IOW, I'm against my own patch. I'll open another ticket for the issue above.

Revision history for this message
foxbunny (bg-branko) wrote :
Revision history for this message
foxbunny (bg-branko) wrote :

Here's a patch based on the fix I submitted for #542568 (https://bugs.launchpad.net/webpy/+bug/542568). The patch fixes the same issue for Cheetah templates, and also makes it possible to use a string instead of a list when specifying dirs for mako (it's backwards compatible).

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.