NoReverseMatch while rendering the Django admin screen?
Running Python 2.5 Django 1.2.4
Error message while testing basic setup. First time I enter the /admin URL in my browser, I get error message:
In template c:\dd\ddproject\src\templates\admin\base_site.html, error at line 10
Caught NoReverseMatch while rendering: Reverse for 'django.contrib.auth.views.logout' with arguments '()' and keyword arguments '{}' not found.
Exception Location: C:\Python25\lib\site-packages\django\template\defaulttags.py in render, line 385
Here's the code at line 10
<开发者_StackOverflow社区;a href="{% url django.contrib.auth.views.logout %}">{% trans 'Log out' %}</a>
I'm reluctant to include my entire settings.py
file. But to answer your next questions, here's the relevant settings:
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
ROOT_URLCONF = 'src.urls'
TEMPLATE_DIRS = (
"/dd/ddproject/src/templates",
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'django.contrib.admindocs',
)
If you're including settings.py
in your question without being prompted, you can't be that much of a newbie :-)
If you're not defining your own login/logout urls, just remember to include the auth
urls in your urls.py
file. Best to do this last:
from django.conf.urls.defaults import *
urlpatterns = patterns('',
# ... other URL defs and includes here ....
(r'', include('django.contrib.auth.urls')),
)
You need to add in urls.py:
#Session management
(r'^login/$','django.contrib.auth.views.login'),
Or maybe you are using
(r'^admin$',include(admin.site.urls)),
(r'^admin/$',include(admin.site.urls)),
instead of :
(r'^admin',include(admin.site.urls)),
I added this line to my urls.py and problem solved:
url('', include('django.contrib.auth.urls')),
I am using Django 1.5
What fixed this for me, was to use absolute paths in INSTALLED_APPS in settings.py. So:
'myproject.myapp',
and not
'myapp',
精彩评论