Reputation: 5946
I'm trying to use the following type approach in an .html file:
<a href="{% url xxx.views.login %}">Login</a>
where I have in urls.py the following:
urlpatterns = patterns('',
# Examples:
(r'^login/$', 'xxx.views.login'),
But I get the following error:
Could not import xxx.views.accounts. View does not exist in module xxx.views.
Not sure if this is something pretty obvious. Is this the correct format for urls?
If I try in urls.py:
(r'^login/$', 'xxx.views.login', name='login'),
with in the .html file:
<a href="{% url 'login' %}">Login</a>
I get the following error:
SyntaxError
Exception Value:
invalid syntax (urls.py, line 13)
If I change the .html file to:
<a href="{% url login %}">Login</a>
I get:
Reverse for 'login' with arguments '()' and keyword arguments '{}' not found.
Upvotes: 1
Views: 172
Reputation: 390
try this:
<a href="{% url 'xxx.views.login' %}"> Login </a>
but the best would be to name the url:
urls.py
url(r'^login/$', 'xxx.views.login', name="login"),
template.html
<a href="{% url login %}">Login</a>
Since 1.5:
<a href="{% url 'login' %}">Login</a>
Upvotes: 1
Reputation: 600059
The error is not with the login URL. It only happens there because the url reverse functionality triggers the import of all your URLs. There is a problem with the URL that references accounts
. Does that view actually exist?
Upvotes: 1