Search code examples
pythondjangodjango-1.4

'admin' is not a registered namespace in Django 1.4


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.

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

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)),

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.

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.

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?


Solution

  • As it turns out, this was due to the order of the TEMPLATE_LOADERS key in my settings file.

    I had the following:

    TEMPLATE_LOADERS = (
        'django.template.loaders.app_directories.Loader',
        'django.template.loaders.filesystem.Loader',
    )
    

    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.

    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.