When I read django code sometimes, I see in some templates "load url from future". I am not quite sure what this is but I do know it has something to do with URLs. How and when is this load url from future supposed to be used?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With