how to use named urls from apps

32 views
Skip to first unread message

Mike

unread,
Nov 29, 2012, 9:32:25 AM11/29/12
to django...@googlegroups.com
I'm trying to use the url template tag to call the login view from contrib.auth.  I've tried the following but none work:

{% url login %}
{% url auth:login %}
{% url auth.login %}
{% url contrib.auth.login %}

Can someone enlighten me please?
Mike


Paul Backhouse

unread,
Nov 29, 2012, 9:54:23 AM11/29/12
to django...@googlegroups.com
Try

{% url 'auth_login' %}

That works for me in Django 1.4

Tom Evans

unread,
Nov 29, 2012, 10:26:58 AM11/29/12
to django...@googlegroups.com
Named urls are URLs defined in your urlconf that have named views. The
contrib auth app, although it provides a bunch of views, does not
automatically install any of them at any URLs, hence this would fail.

If you include the login view in one of your urlconfs, it will not
have the 'auth' app label, it will have whatever name you decide to
give it.

Cheers

Tom

PS: The fully qualified view name may have worked -
"django.contrib.auth.views.login". There is a function at
"django.contrib.auth.login", but that function is used to actually log
users in, not to present a login form and process it.

Mike

unread,
Nov 29, 2012, 10:59:40 AM11/29/12
to django...@googlegroups.com, teva...@googlemail.com

Named urls are URLs defined in your urlconf that have named views. The
contrib auth app, although it provides a bunch of views, does not
automatically install any of them at any URLs, hence this would fail.

If you include the login view in one of your urlconfs, it will not
have the 'auth' app label, it will have whatever name you decide to
give it.

Cheers

Tom

That makes sense, and explains why none of my solutions worked.  The solution provided by Paul Backhouse works, I suppose because it is referring to the view function and not the url name.


Chris Cogdon

unread,
Nov 30, 2012, 6:21:06 PM11/30/12
to django...@googlegroups.com
And, don't forget, the form is:

{% load url from future %}
{% url 'auth_login' %}

OR

{% url auth_login %}

The former is highly recommend, as the latter is deprecated and will become the default in a future Django release.

If you ever get messages such as "view not found for reverse"... this has been my culprit 90% of the time.
Reply all
Reply to author
Forward
0 new messages