渲染 Django 管理屏幕时没有ReverseMatch?
运行 Python 2.5 Django 1.2.4
测试基本设置时出现错误消息。第一次在浏览器中输入 /admin URL 时,我收到错误消息:
在模板 c:\dd\ddproject\src\templates\admin\base_site.html 中,第 10 行出错
渲染时捕获 NoReverseMatch:未找到参数“()”和关键字参数“{}”的“django.contrib.auth.views.logout”的反向。
异常位置:渲染中的 C:\Python25\lib\site-packages\django\template\defaulttags.py,第 385 行
这是第 10 行的代码,
<a href="{% url django.contrib.auth.views.logout %}">{% trans 'Log out' %}</a>
我不愿意包含整个 settings.py
文件。但为了回答您的下一个问题,以下是相关设置:
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',
)
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
<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',
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您在没有提示的情况下在问题中包含
settings.py
,那么您就不是新手了 :-)如果您没有定义自己的登录/注销网址,请记住将
auth
url 包含在urls.py
文件中。最好最后执行此操作: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 yoururls.py
file. Best to do this last:您需要添加 urls.py:
或者您可能正在使用
而不是:
,include(admin.site.urls)),而不是:
,'django.contrib.auth.views.login'),或者您可能正在使用
而不是:
You need to add in urls.py:
Or maybe you are using
instead of :
,include(admin.site.urls)),instead of :
,'django.contrib.auth.views.login'),Or maybe you are using
instead of :
我将此行添加到我的 urls.py 中并解决了问题:
url('', include('django.contrib.auth.urls')),
我正在使用 Django 1.5
I added this line to my urls.py and problem solved:
url('', include('django.contrib.auth.urls')),
I am using Django 1.5
对我来说解决这个问题的方法是在 settings.py 中的 INSTALLED_APPS 中使用绝对路径。所以:
而不是
What fixed this for me, was to use absolute paths in INSTALLED_APPS in settings.py. So:
and not