Django管理页面不显示
我一直在跟着教程学习,直到应该有一个管理员后台的登录页面为止。http://docs.djangoproject.com/en/dev/intro/tutorial02/
但是我看到的是这样的欢迎页面:
我已经在INSTALLED_APPS里启用了管理员应用,数据库也同步了,还调整了urls.py,所以我不太确定问题出在哪里。
我是在使用apache2和mod_wsgi运行的。
urls.py:
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Example:
# (r'^testproject/', include('testproject.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
)
Settings.py:
...
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
'polls'
)
...
表格:
数据库已更改
mysql> SHOW TABLES;
+----------------------------+
| Tables_in_django_test |
+----------------------------+
| auth_group |
| auth_group_permissions |
| auth_message |
| auth_permission |
| auth_user |
| auth_user_groups |
| auth_user_user_permissions |
| django_admin_log |
| django_content_type |
| django_session |
| django_site |
| polls_choice |
| polls_poll |
+----------------------------+
4 个回答
2
我遇到了一个一样的错误。虽然我请求的是 domain.com/admin,但我只看到了欢迎页面。不太确定我们的错误是否是因为源代码相同,因为我是在hostgator上用mod_fcgid运行我的django网站。
不过,我通过为python添加更具体的自定义路径解决了我的问题,直到包含我的wsgi.py文件的目录。
我的index.fcgi文件是:
...
# Add a custom Python path. (optional)
sys.path.insert(0, "/home/*username*/django")
# Switch to the directory of your project.
...
现在变成了:
...
# Add a custom Python path. (optional)
sys.path.insert(0, "/home/*username*/django")
sys.path.insert(0, "/home/*username*/django/mysite")
sys.path.insert(0, "/home/*username*/django/mysite/mysite")
# Switch to the directory of your project.
...
我猜这是因为欢迎页面的代码在路径列表中比管理员代码的位置更靠前。
4
如果你是通过Apache和mod_wsgi来做这个,那你就没有按照教程来。教程让你使用开发服务器,这是有原因的:因为用Apache的话,每次你修改代码都需要手动重启它。而开发服务器会自动检测到变化,并自己重启,这样就方便多了。
5
这两行真的只缩进了一个空格吗?就像你帖子里显示的那样?
from django.contrib import admin
admin.autodiscover()
如果这样做的话,你会遇到缩进错误。把它们靠左边对齐就行了。
后来:哦,我在上面的评论里看到你发现了这个缩进错误。把我的回答标记为社区共享。