Reverse for ‘django.contrib.auth.views.login’のエラー解消-Django


Djangoのユーザ認証まとめ – c-bata web
を参考に、ログインのフォームを作成している時に、
NoReverseMatch at /accounts/login/

Reverse for 'django.contrib.auth.views.login' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

Request Method: GET
Request URL: http://maps.dependa.io:8000/accounts/login/?next=/field/
Django Version: 1.8.3
Exception Type: NoReverseMatch
Exception Value:

Reverse for 'django.contrib.auth.views.login' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

Exception Location: /home/ec2-user/loginapp/loginappenv/lib/python3.4/site-packages/django/core/urlresolvers.py in _reverse_with_prefix, line 496
Python Executable: /home/ec2-user/loginapp/loginappenv/bin/python
Python Version: 3.4.3
Python Path:

['/home/ec2-user/loginapp',
'/home/ec2-user/loginapp/loginappenv/lib/python34.zip',
'/home/ec2-user/loginapp/loginappenv/lib/python3.4',
'/home/ec2-user/loginapp/loginappenv/lib/python3.4/plat-linux',
'/home/ec2-user/loginapp/loginappenv/lib/python3.4/lib-dynload',
'/home/ec2-user/.pyenv/versions/3.4.3/lib/python3.4',
'/home/ec2-user/.pyenv/versions/3.4.3/lib/python3.4/plat-linux',
'/home/ec2-user/loginapp/loginappenv/lib/python3.4/site-packages']

Server time: Mon, 27 Jul 2015 13:36:07 +0000

Error during template rendering

In template /home/ec2-user/loginapp/templates/accounts/login.html, error at line 9
Reverse for 'django.contrib.auth.views.login' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

というエラーが出た。

原因は、
<form method="post" action="
{% url 'django.contrib.auth.views.login' %}
">

の部分。

上記を、

<form method="post" action="{% url 'accounts:django.contrib.auth.views.login' %}">
としたらエラーが解消された。

具体的には、
‘django.contrib.auth.views.login’

‘accounts:django.contrib.auth.views.login’
に変更。

accountsは、urls.pyで指定したnamespace。

具体的には以下の部分。
url(r'^accounts/', include('apps.accounts.urls', namespace='accounts')),

・参考
django – no reverse match for login view – codeotel.com
django – no reverse match for login view – Stack Overflow