Take the 2-minute tour ×

Why did the django core developers allow the url templatetag to point directly to a django view function? (reference - https://docs.djangoproject.com/en/dev/ref/templates/builtins/#url)

{% load url from future %}

{# 1st method: pointing to a view function #}
{% url 'app_views.client' %}

{# 2nd method: pointing to a named url #}
{% url 'myapp:view-name' %}

One can already name the url in urls.py and hence use the 2nd method to point to a specific url. It doesn't feel right to allow developers to actually reference a view function directly from the template.

Does anyone know why this decision was made?

share|improve this question
It might be worth posting this on the Django users Google group? –  Spycho Aug 17 '11 at 11:08

2 Answers 2

up vote 2 down vote accepted

Passing a dotted view function name to the {% url %} template tag is simply the form the template tag took in the earlier days of Django, before you could name URLs. It's still supported, though as you point out, you probably wouldn't use it in a modern application.

share|improve this answer
Aha. So it's simply to be backwards compatible. Thanks for the info. –  Calvin Cheng Aug 17 '11 at 10:38
Yeah, but that's not new in 1.3. The view-style url tag was around as long as Django has been, and the named-style was introduced long before Django's milestone release back in the 0.9.x days. –  Chris Pratt Aug 17 '11 at 15:01

URLs in Django are just mappings to views. Therefore, in the template, using a named URL is just indirectly referencing the view anyway.

The exception is where a single view is mapped to by multiple URLs.

Also note that they are planning to change the syntax of the url tag in 1.5. It will take a context variable as the parameter, rather than a string. It will still take views or named URLs though.

share|improve this answer
It feels cleaner to have just "1 place" where I can intuitively find my named urls. Namely in my "urls.py" files. Working in the context of a development team, these little bits of conventions increases efficiency and reduces cost of coordination too. Personally, I would avoid using the 1st method in my templates as far as possible. Which was why I was puzzled it was even supported in the first place... –  Calvin Cheng Aug 17 '11 at 10:41
If, instead of the convention of always using named URLs, you go with the convention of always using view names, it's effectively the same thing but without having to actually name the URLs. Less code! –  Spycho Aug 17 '11 at 10:47

Your Answer


