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?
It’s because you left out a
/inurls.py. Change the admin line to the following:I checked this on my server and got the same error with your line from
urls.py.