Opened 19 years ago
Closed 19 years ago
#1518 closed enhancement (wontfix)
using different TEMPLATE_FILE_EXTENSION would be nice
Reported by: | anonymous | Owned by: | Adrian Holovaty |
---|---|---|---|
Component: | Template system | Version: | |
Severity: | minor | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
building a site that partly consists of svg would be easier if the TEMPLATE_FILE_EXTENSION could be set differently. perhaps a parameter to render_to_response() would do, better would be some aproach to set it via urlpatterns.
Change History (6)
comment:1 by , 19 years ago
comment:2 by , 19 years ago
mmh, i don't like the 'check a list of possibilities'-solution. it's error prune and may not always do what i want.
question is: how is the content-type determined? this question also raises if i use other format than html in the templates anyway. as mentioned in the docs i can use cvs, xml whatever. but how do i control the content-type send to the browser?
second thing: i would like to use one view with different templates. perhaps i want to see same content as html, xhtml and svg. driven, say by url. maybe a url matcher looks like this:
urlpatterns = patterns(,
(r'check(?P<TEMPLATE_FILE_EXTENSION>(.html|.xhtml|.svg))$', 'polls.views.check'),
...
this way you can use
http://localhost:8080/polls/check.html
for a rendered page in html or
http://localhost:8080/polls/check.svg
for the same content rendered in svg. this must neither be the extension in the url nor be always driven by the urlpatterns.
comment:3 by , 19 years ago
The patch I submitted for #500 doesn't do a 'check a list', it gives the option of explicitly specifying an extension.
Regarding content-type, you can pass it with an HTTPResponse (see #1504 for a render_to_response request) in your view.
Using one view with different templates isn't really an issue of TEMPLATE_FILE_EXTENSION - you can render whatever you like in your view using your regex value.
comment:4 by , 19 years ago
this:
22 for template_ext in TEMPLATE_FILE_EXTENSIONS:
23 filepath = os.path.join(template_dir, template_name) + template_ext
24 try:
25 return open(filepath).read()
26 except IOError:
27 pass
looks for me like a loop to check if a file exists with a extension from a list. did i misinterpret that?
shure i can pass content-type with HTTPResponse but i would like to have an automatic mapping. probably by extension as other do also (apache, java-webapps, ...) or for example by a tag in the template.
no, you can't render anything you want. it must end in an extension given by TEMPLATE_FILE_EXTENSION. i talk about the template, not the url-path.
i was looking for a deterministic way to have different templates for one view with probably different content-types. i wouldn't like to branch to different templates and set different contenttypes in every view i have. how would you do that today?
comment:5 by , 19 years ago
That was JanC's patch, not mine. My one means you don't have to rely on TEMPLATE_FILE_EXTENSION, you just explicitly specify an extension. It has also been discussed to change the template system so that you must specify the extension explicitly. I'm warming to this idea.
I like your idea about setting the content-type based on extension, but that should be a new ticket.
comment:6 by , 19 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Now that TEMPLATE_FILE_EXTENSION is gone, I doubt this will happen.
is the latest patch in #500 enough to satisfy this craving?