'admin'不是Django 1.4中的注册名称空间 [英] 'admin' is not a registered namespace in Django 1.4
问题描述
我正在尝试将一个很大的Django项目升级到新发布的Django 1.4,并且在运行python manage.py test
时遇到一些问题.
I'm attempting to upgrade quite a large Django project to the newly released Django 1.4, and I'm having some issues when running python manage.py test
.
在Django 1.3中通过的许多内部测试现在都失败了,出现了一些我似乎无法修复的奇怪消息.出现次数最多的是:
Lots of the internal tests which passed in Django 1.3 are now failing, with really odd messages that I can't seem to fix. One that appears the most is:
NoReverseMatch: u'admin' is not a registered namespace
这是为django.contrib.auth
测试(尤其是更改密码)而进行的测试(其中之一是test_password_change_fails_with_mismatched_passwords (django.contrib.auth.tests.views.ChangePasswordTest)
.奇怪的是,名称空间已正确注册,并且应用程序功能正常.我将admin导入到新"方式:
This is raised for the django.contrib.auth
tests for password changing in particular (one of which is test_password_change_fails_with_mismatched_passwords (django.contrib.auth.tests.views.ChangePasswordTest)
. The strange thing is, the namespace is registered correctly and the application functions just fine. I am importing admin in the "new" way:
url(r'^admin/', include(admin.site.urls)),
当我特别搜索此错误时,我所能找到的就是使用旧方案导入管理URL的人,根本没有与此问题有关的东西.
When I Google this error in particular, all I can find is people importing the admin URLs using the old scheme, and nothing relating to this issue at all.
我曾经尝试过从INSTALLED_APPS
一次删除应用程序,但是auth测试根本无法通过.另外,当我从python manage.py shell
加载Python解释器并执行reverse('admin:index')
时,URL解析为/admin/
且没有错误.我已经仔细阅读了代码,看不到可能会下降到什么地方.
I've tried removing apps from INSTALLED_APPS
one by one, but the auth tests simply won't pass. Also, when I load a Python interpreter from python manage.py shell
and execute reverse('admin:index')
the URL resolves to /admin/
with no errors. I've read through the code extensively, and can't see where this can be falling down.
正如我之前提到的,这不是唯一发生的错误.即使在我的settings.py
文件中定义了AUTH_PROFILE_MODULE
,我也从test_site_profile_not_available (django.contrib.auth.tests.models.ProfileTestCase)
测试中获得了AttributeError: AUTH_PROFILE_MODULE
. Django自己的测试怎么会这样失败?
As I mentioned earlier, this isn't the only error that's occurring. I'm also getting AttributeError: AUTH_PROFILE_MODULE
from the test_site_profile_not_available (django.contrib.auth.tests.models.ProfileTestCase)
test, even though AUTH_PROFILE_MODULE
is defined in my settings.py
file. How can Django's own tests be failing like this?
推荐答案
事实证明,这是由于设置文件中TEMPLATE_LOADERS
键的顺序所致.
As it turns out, this was due to the order of the TEMPLATE_LOADERS
key in my settings file.
我有以下内容:
TEMPLATE_LOADERS = (
'django.template.loaders.app_directories.Loader',
'django.template.loaders.filesystem.Loader',
)
,这在某种程度上导致了反向管理URL时导致的错误.切换两个回合解决了这个问题.我很想知道这是怎么发生的,因为在空白的Django 1.4项目中无法重现.
which, somehow, caused the error when reversing admin URLs. Switching the two round solved the issue. I would love to know how this happens, as it isn't reproducible in a blank Django 1.4 project.
可重复的 是settings.AUTH_PROFILE_MODULE
的AttributeError
.事实证明,这是Django 1.4中的一个错误,该错误是在发布日此处提交的.
What was reproducible, however, was the AttributeError
for settings.AUTH_PROFILE_MODULE
. Turns out this is a bug in Django 1.4, which was filed on release day here.
这篇关于'admin'不是Django 1.4中的注册名称空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!