BenjaminGolder
BenjaminGolder

Reputation: 1592

django admin shows all apps, models, but admin model pages return 404

These urls work:

/admin
/admin/appname

But this does not work for any model, including users, groups, or sites:

/admin/appname/modelname

For example, /admin/auth works and shows the Groups, and Users models, but if I click on either model, navigating to admin/auth/user, I receive a 404 not found error.

I first assumed that it was probably a problem in urls.py so I commented out everything out besides the admin. It made no difference. Here's my urls.py file:

from django.conf.urls.defaults import *
from django.contrib import admin

urlpatterns = patterns('',
    # main admin
    (r'^admin/', include(admin.site.urls)),
)
admin.autodiscover()

Here's my installed apps, in settings.py:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
    'south',
)

I have of course already tried shutting down the server, running syncdb, (as well as running south migrations for apps that were using south), and using runserver again. It makes no difference.

I also tried uninstalling and reinstalling django (same version, 1.3).

Django tried these URL patterns, in this order:

  1. ^admin/ ^$ [name='index']
  2. ^admin/ ^logout/$ [name='logout']
  3. ^admin/ ^password_change/$ [name='password_change']
  4. ^admin/ ^password_change/done/$ [name='password_change_done']
  5. ^admin/ ^jsi18n/$ [name='jsi18n']
  6. ^admin/ ^r/(?P<content_type_id>\d+)/(?P<object_id>.+)/$
  7. ^admin/ ^(?P<app_label>\w+)/$ [name='app_list']

The current URL, admin/auth/user/, didn't match any of these.

Upvotes: 2

Views: 746

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599610

As I mentioned in my comment, you apparently need to have the admin.autodiscover() line before the place where you include it in the urlpatterns tuple.

This seems to be because the code that calculates the urls for each app/model - admin.sites.AdminSite.get_urls - depends on the models already being registered for the admin before it runs. If not, the relevant URLs are not created.

Upvotes: 4

Related Questions