Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why won't Django 1.0 admin application work?

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?

like image 252
Josh Smeaton Avatar asked Oct 31 '08 03:10

Josh Smeaton


People also ask

How do I run Django admin?

To login to the site, open the /admin URL (e.g. http://127.0.0.1:8000/admin ) and enter your new superuser userid and password credentials (you'll be redirected to the login page, and then back to the /admin URL after you've entered your details).

What is the default username and password for Django admin?

Run 'python manage.py migrate' to apply them. Username (leave blank to use 'chatru'): admin Email address: [email protected] Password: Password (again): The password is too similar to the username.

Can I use Django admin in production?

your company should follow a least access principle policy; so yes: only select people should have access. Django has basic auditing capability via signals and displayed in the admin out of the box. You can build on top of this.

Can I use Django admin as frontend?

Django Admin is one of the most important tools of Django. It's a full-fledged application with all the utilities a developer need. Django Admin's task is to provide an interface to the admin of the web project. Django's Docs clearly state that Django Admin is not made for frontend work.


1 Answers

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.

like image 57
tghw Avatar answered Oct 12 '22 19:10

tghw