2
votes

I am doing the tango with django tutorial. I am up to chapter 5 on working with models and I am setting up the admin website. I get this strange error:

ImportError: cannot import name get_permission_codename

This seems to go away when I remove the

admin.autodiscover()

from my project/urls.py. But I am concerned that I will need this down the road.

Here is the Traceback I get when I run the development server:

Environment:

Request Method: GET Request URL: http://127.0.0.1:8000/admin/

Django Version: 1.5.4 Python Version: 2.7.3 Installed Applications: ('django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.admin', 'rango') Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware')

Traceback: File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response 103. resolver_match = resolver.resolve(request.path_info) File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve 319. for pattern in self.url_patterns: File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in url_patterns 347. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in urlconf_module 342. self._urlconf_module = import_module(self.urlconf_name) File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module 35. import(name) File "/home/gpanterov/MyProjects/django/tango_with_django_project/tango_with_django_project/urls.py" in 6. admin.autodiscover() File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/init.py" in autodiscover 29. import_module('%s.admin' % app) File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module 35. import(name) File "/usr/local/lib/python2.7/dist-packages/django/contrib/contenttypes/admin.py" in 5. from django.contrib.admin.checks import InlineModelAdminChecks File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/checks.py" in 6. from django.contrib.admin.utils import get_fields_from_path, NotRelationField, flatten File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/utils.py" in 6. from django.contrib.auth import get_permission_codename

Exception Type: ImportError at /admin/ Exception Value: cannot import name get_permission_codename

When I remove the admin.autodiscover() line, the development server runs and I am able to get to the admin panel, but when I log in with the superuser password I created earlier, I get the message "You don't have permission to edit anything." and I don't see any of the categories I created.

2

2 Answers

4
votes

I got this error when downgrading django from latest version (1.8) to an old version (1.4) for testing.

The problem here is that git doesn't delete .pyc files when switching branches (because they are .gitignore'ed) and python only regenerates them when the corresponding .py file is newer than the .pyc file (see this question for details).

The solution is to delete all *.pyc files in django/contrib/admin and django/contrib/contenttypes directories.

0
votes

cannot import name get_permission_codename

Make sure u have not install all the version of django in your system. if there then remove all and install fresh django