渲染 Django 管理屏幕时没有ReverseMatch?

发布于 2024-11-05 07:00:38 字数 1224 浏览 1 评论 0原文

运行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

乖乖 2024-11-12 07:00:38

如果您在没有提示的情况下在问题中包含 settings.py,那么您就不是新手了 :-)

如果您没有定义自己的登录/注销网址,请记住将 auth url 包含在 urls.py 文件中。最好最后执行此操作:

from django.conf.urls.defaults import *

urlpatterns = patterns('',
    # ... other URL defs and includes here ....
    (r'', include('django.contrib.auth.urls')),
)

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')),
)
疾风者 2024-11-12 07:00:38

您需要添加 urls.py:

#Session management
(r'^login/

或者您可能正在使用

(r'^admin

而不是:

(r'^admin',include(admin.site.urls)),
,'django.contrib.auth.views.login'),

或者您可能正在使用


而不是:


,include(admin.site.urls)),
(r'^admin/

而不是:


,'django.contrib.auth.views.login'),

或者您可能正在使用

而不是:

,include(admin.site.urls)),

而不是:

,'django.contrib.auth.views.login'),

或者您可能正在使用

而不是:

You need to add in urls.py:

#Session management
(r'^login/

Or maybe you are using

(r'^admin

instead of :

(r'^admin',include(admin.site.urls)),
,'django.contrib.auth.views.login'),

Or maybe you are using


instead of :


,include(admin.site.urls)),
(r'^admin/

instead of :


,'django.contrib.auth.views.login'),

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 :

澉约 2024-11-12 07:00:38

我将此行添加到我的 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

嘴硬脾气大 2024-11-12 07:00:38

对我来说解决这个问题的方法是在 settings.py 中的 INSTALLED_APPS 中使用绝对路径。所以:

'myproject.myapp',

而不是

'myapp',

What fixed this for me, was to use absolute paths in INSTALLED_APPS in settings.py. So:

'myproject.myapp',

and not

'myapp',
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文