Django 1.4和NoReverseMatch at / admin / error [英] Django 1.4 and NoReverseMatch at /admin/ error

查看:211
本文介绍了Django 1.4和NoReverseMatch at / admin / error的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在更新到Django 1.4之后尝试访问我的管理面板时,我收到此错误 - 错误是:

  NoReverseMatch在/ admin / 
反转'logout'与参数'()'和关键字参数'{}'未找到。

我最好的猜测是我正在定义一个注销urlpattern,与某个管理员面板正试图创造?虽然,应该是创建/管理/注销,对吧?我将ADMIN_MEDIA_PREFIX更新为STATIC_URL,并将它们移动到一个名为admin的子文件夹,但这似乎没有什么不同。



在我的urls.py中,我有:

  from django.contrib import admin 
admin.autodiscover()

urlpatterns = patterns('',
...
('^ logout / $',RedirectView.as_view(url ='/ login / index.html')),
(r' ^登录/(?P<路径>。*)$','django.views.static.serve',{'document_root':'/ fullpath / to / media / login'}),
(r' ^静态/(?P< path>。*)$','django.views.static.serve',{'document_root':'/ fullpath / to / media / static'}),
(r' ^ admin /(.*)',include(admin.site.urls)),

在我的settings.py中,我有:

  STATIC_ROOT ='/ fullpath / to / myapp / media / static /'
STATIC_URL ='/ static /'

INSTALLED_APPS =(
'django.contrib.auth',
...
'django.contrib.admin',


解决方案

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

应该是

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

(。*)将把所有跟随admin的任何东西作为视图参数



另外,你知道什么叫 reverse('logout')?在我本地的1.4安装中,管理员是命名空间,我必须调用 reverse('admin:logout')


I am getting this error when trying to access my admin panel after updating to Django 1.4 - the error is:

NoReverseMatch at /admin/
Reverse for 'logout' with arguments '()' and keyword arguments '{}' not found.

My best guess is that I'm defining a logout urlpattern which is somehow conflicting with the one the admin panel is trying to create? Although, it should be creating /admin/logout, right? I did update my ADMIN_MEDIA_PREFIX to STATIC_URL and moved them to a sub-folder called admin, but that didn't seem to make a difference.

In my urls.py, I have:

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    ...
    ('^logout/$',  RedirectView.as_view(url='/login/index.html')),
    (r'^login/(?P<path>.*)$', 'django.views.static.serve', {'document_root': '/fullpath/to/media/login'}),
    (r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': '/fullpath/to/media/static'}),
    (r'^admin/(.*)', include(admin.site.urls)),
)

And in my settings.py, I have:

STATIC_ROOT = '/fullpath/to/myapp/media/static/'
STATIC_URL = '/static/'

INSTALLED_APPS = (
    'django.contrib.auth',
     ...
    'django.contrib.admin',
)

解决方案

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

Should be

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

(.*) would eat up all anything following admin as the view argument.

Also, do you know what is calling reverse('logout')? In my local 1.4 install, the admin is namespaced and I have to call reverse('admin:logout')

这篇关于Django 1.4和NoReverseMatch at / admin / error的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆