Changes between Version 100 and Version 101 of RemovingTheMagic


Ignore:
Timestamp:
04/15/2006 11:45:11 AM (9 years ago)
Author:
adrian
Comment:

Added "Include template extension explicitly" section

Legend:

Unmodified
Added
Removed
Modified
  • RemovingTheMagic

    v100 v101  
    186186p.save()
    187187}}}
     188
     189=== Include template extension explicitly ===
     190
     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.
     192
     193Given a template {{{polls/poll_detail.html}}}...
     194
     195Old:
     196{{{
     197get_template('polls/poll_detail')
     198select_template(['polls/poll_detail', 'polls/poll_detail2'])
     199render_to_response('polls/poll_detail', {'poll': p})
     200}}}
     201
     202New:
     203
     204{{{
     205get_template('polls/poll_detail.html')
     206select_template(['polls/poll_detail.html', 'polls/poll_detail2.html'])
     207render_to_response('polls/poll_detail.html', {'poll': p})
     208}}}
     209
     210This is changed in templates themselves, too -- notably in the {{{ {% extends %} }}} and {{{ {% include %} }}} template tags:
     211
     212Old:
     213{{{
     214{% extends "base" %}
     215{% include "some_snippet" %}
     216}}}
     217
     218New:
     219{{{
     220{% extends "base.html" %}
     221{% include "some_snippet.html" %}
     222}}}
     223
     224As a result of this change, the {{{TEMPLATE_FILE_EXTENSION}}} setting is gone, because there's no need for it.
     225
     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.
     227
     228All the templates for the {{{django.contrib}}} apps -- most notably, the admin site -- still use {{{.html}}} extensions.
     229
     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')}}}.
     231
     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.
    188233
    189234=== Namespace simplification ===
Back to Top