Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly reverse the Django auth login?

Ok, so all I want to do is to redirect the user to the login page based on some logic in my view. I've tried:

reverse('django.contrib.auth.views.login')

and I've also tried creating a unique entry in my app's urls.py

from django.contrib.auth.views import login
urlpatterns = patterns('',
    url(r'^login/', login, name='my-login'),
)

Then in my view

reverse('my-login')

but they both give me a NoReverseMatch error.

What is the proper way to do this?

like image 299
Josh Russo Avatar asked Jun 08 '11 05:06

Josh Russo


1 Answers

There's definitely something wrong elsewhere in your urls. I'm able to reverse the auth login url pattern just fine:

from django.core.urlresolvers import reverse
print reverse('django.contrib.auth.views.login')
like image 124
Brandon Avatar answered Sep 30 '22 11:09

Brandon