views:

1887

answers:

1

I've just started playing with Django and am loosely following the tutorial with my own set of basic requirements. The models I've sketched out so far are a lot more comprehensive than the tutorial, but they compile fine. Otherwise, everything should have been the same.

My problem is with the admin application. I can log into it, and view the editable models, but when I click on a model or any of the change/add buttons, I get a 404.

This is the exact error I get:

Page not found (404)
Request Method:     GET
Request URL:    http://localhost:8000/admin/auth/user/add/

App u'', model u'auth', not found.

These are the relevant files and what is in them:

urls.py

from django.conf.urls.defaults import *

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
# Example:
# (r'^daso/', include('daso.foo.urls')),

# Uncomment the admin/doc line below and add 'django.contrib.admindocs' 
# to INSTALLED_APPS to enable admin documentation:
#(r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:
    (r'^admin(.*)', admin.site.root)
)

admin.py

from daso.clients.models import Person, Client, Contact
from django.contrib import admin

admin.site.register(Person)
admin.site.register(Client)
admin.site.register(Contact)

models.py - I'll just show one model

class Client(Person):
relationships = models.ManyToManyField("Contact", through="Relationship", null=True)
disabilities = models.ManyToManyField("Disability", related_name="disability", null=True)
medical_issues = models.ManyToManyField("MedicalIssue", related_name="medical_issue", null=True)
medicare_num = models.CharField(max_length=15, blank=True)
insurance = models.OneToOneField("Insurance", null=True, blank=True)
medications = models.ManyToManyField("Medication", through="Medication_Details", null=True)

def __unicode__(self):
 client = u"[Client[id: ", self.id, " name: ", self.first_name, " ", self.last_name, "]"
 return client

settings.py

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.admin',
    'daso.clients',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
)

Those should be the relevant files/sections of files. If anyone has an idea about WHY I'm getting a 404, please enlighten me?

Note, when pasting in here, installed apps had the last 2 apps tabbed instead of spaced*4, and when reloading the admin page it worked for half a second then 404'd again. Strange. Ideas?

+11  A: 

It's because you left out a / in urls.py. Change the admin line to the following:

(r'^admin/(.*)', admin.site.root),

I checked this on my server and got the same error with your line from urls.py.

tghw
wow.. thank you! I feel pretty stupid now though the error is not very helpful
Josh Smeaton
It's an odd error, probably worth reporting a bug. I still don't fully understand why it would work for most pages, but break on some. My guess is that it's not handling '/' properly a few "directories" deep.
tghw
this also works when your admin change password and logout do not take the absolute path and go to a 404
Rasiel