为什么Django 1.0管理应用无法工作?
我刚开始接触Django,并且根据自己的基本需求在跟着教程做一些尝试。我目前设计的模型比教程中的要复杂得多,但它们都能正常编译。除此之外,其他的应该都是一样的。
我遇到的问题是在管理应用上。我可以登录进去,看到可以编辑的模型,但当我点击某个模型或者任何更改/添加的按钮时,就会出现404错误。
这是我收到的具体错误信息:
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/admin/auth/user/add/
App u'', model u'auth', not found.
这些是相关的文件以及它们的内容:
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 - 我只展示一个模型
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',
)
这些应该是相关的文件或文件的部分。如果有人知道我为什么会出现404错误,请告诉我一下?
注意,当我在这里粘贴时,已安装的应用最后两个应用是用制表符而不是空格*4来缩进的,重新加载管理页面时,它能工作半秒钟,然后又出现404错误。真奇怪。有什么想法吗?
1 个回答
12
这是因为你在 urls.py
文件里漏掉了一个 /
。把管理员那一行改成下面这样:
(r'^admin/(.*)', admin.site.root),
我在我的服务器上检查了一下,发现用你在 urls.py
里的那一行也出现了同样的错误。