Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django url template tag: 'module' object has no attribute 'views'

The tag in question:

< a href="{% url django.contrib.auth.views.login %}">Login< /a>

URLConf:

from django.contrib.auth import views <br />
...<br />
(r'^login/$',views.login, {'redirect_field_name' : '/' })
<br />...
like image 251
SapphireSun Avatar asked Jan 22 '23 23:01

SapphireSun


2 Answers

it's better to use named urls, they save a lot of maintenance work in the future and typing in the first place.

if you keep name of the url the same, you can rename view function, move it to a different app, etc. you won't need to change templates or other places using this url at all.

in urls.py:

url(r'^login/',path.to.view,name='login',...)

in templates:

<a href="{%url login%}">login here</a>

in views:

login_url = reverse('login')
like image 52
Evgeny Avatar answered May 09 '23 10:05

Evgeny


For some reason it didn't like the way I was importing it.

Solution:

from django.contrib.auth.views import login

(r'^login', login, etc.)
like image 31
SapphireSun Avatar answered May 09 '23 12:05

SapphireSun