Changes between Version 100 and Version 101 of RemovingTheMagic

04/15/06 11:45:11 (11 years ago)
Adrian Holovaty

Added "Include template extension explicitly" section


  • RemovingTheMagic

    v100 v101
     189=== Include template extension explicitly ===
     191Now, whenever referencing templates by name, you now pass the template's *full name* -- including its extension -- instead of the file's name without an extension.
     193Given a template {{{polls/poll_detail.html}}}...
     198select_template(['polls/poll_detail', 'polls/poll_detail2'])
     199render_to_response('polls/poll_detail', {'poll': p})
     206select_template(['polls/poll_detail.html', 'polls/poll_detail2.html'])
     207render_to_response('polls/poll_detail.html', {'poll': p})
     210This is changed in templates themselves, too -- notably in the {{{ {% extends %} }}} and {{{ {% include %} }}} template tags:
     214{% extends "base" %}
     215{% include "some_snippet" %}
     220{% extends "base.html" %}
     221{% include "some_snippet.html" %}
     224As a result of this change, the {{{TEMPLATE_FILE_EXTENSION}}} setting is gone, because there's no need for it.
     226Clearly, this also means you can start putting whatever extension you want on templates. So if you'd like your templates to have a {{{.txt}}} extension, go for it. If you'd like to keep using {{{.html}}}, that's fine too. If you want to invent your own extension, or not even *use* an extension, be our guest.
     228All the templates for the {{{django.contrib}}} apps -- most notably, the admin site -- still use {{{.html}}} extensions.
     230Custom template tags created via {{{inclusion_tag()}}} should note the explicit template name (with the extension). For example, use {{{inclusion_tag('foo/bar.html')}}} instead of {{{inclusion_tag('foo/bar')}}}.
     232Finally, note the syndication framework, which looks for templates with the name of the slug of each feed, now requires an '.html' extension on those templates. For example, if your feed has a slug {{{"hello"}}}, the syndication framework will look for the templates {{{feeds/hello_title.html}}} and {{{feeds/hello_description.html}}}. This is backwards-compatible.
    189234=== Namespace simplification ===
Back to Top