10π
Itβs due to a change to the url
tag enacted in 1.3:
Changes to
url
andssi
Most template tags will allow you to pass in either constants or variables as arguments β for example:
{% extends "base.html" %}
allows you to specify a base template as a constant, but if you have a context variable
templ
that contains the valuebase.html
:{% extends templ %}
is also legal.
However, due to an accident of history, the
url
andssi
are different. These tags use the second, quoteless syntax, but interpret the argument as a constant. This means it isnβt possible to use a context variable as the target of aurl
andssi
tag.Django 1.3 marks the start of the process to correct this historical accident. Django 1.3 adds a new template library β
future
β that provides alternate implementations of theurl
andssi
template tags. Thisfuture
library implement behavior that makes the handling of the first argument consistent with the handling of all other variables. So, an existing template that contains:{% url sample %}
should be replaced with:
{% load url from future %} {% url 'sample' %}
The tags implementing the old behavior have been deprecated, and in Django 1.5, the old behavior will be replaced with the new behavior. To ensure compatibility with future versions of Django, existing templates should be modified to use the new
future
libraries and syntax.
5π
I will put this in a separate answer due to the following salient Exception in connection with templates:
If you get a django.core.urlresolvers.NoReverseMatch
Exception thrown from within a django template (Django version >1.4) parser, it may just be the usage of {% load url from future %}
within the template.
In this case, simply quote the url that is passed to the url-tag. That is {% url someurl %}
should become {% url 'someurl' %}
. Thanks to Ignacio VA for pointing me in that direction.
- [Django]-Django: why i can't get the tracebacks (in case of error) when i run LiveServerTestCase tests?
- [Django]-Detect mobile, tablet or Desktop on Django
- [Django]-Django 1.7 β App 'your_app_name' does not have migrations