Django admin page not showing
I've been following the polls tutorial up until the point where I should have a login page for the admin backend. http://docs.djangoproject.com/en/dev/intro/tutorial02/
Instead I get the welcome page like this:
I have enabled the admin app in INSTALLED_APPS, synced the db and tweaked urls.py so I'm not sure what the problem is.
Running apache2 with mod_wsgi.
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'^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'
)
...
Tables:
Database changed
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 |
+----------------------------+
Are these two lines really indented one space, as appears in your post?
from django.contrib import admin
admin.autodiscover()
You'll get an IndentationError if you do that. Put them flush against the left margin.
Later: Oh I see in a comment above that you found this indentation error. Marking my answer as community wiki.
If you're doing this via Apache and mod_wsgi, then you're not following the tutorial. The tutorial tells you to use the development server, for a good reason: with Apache, you need to restart it whenever you make a code change. The dev server detects changes and restarts itself for you.
I had an identical error. I only got the welcome page even though I requested domain.com/admin. Not sure if our errors are due to identical sources though because I'm running my django site on hostgator with mod_fcgid.
Anyway, solved my problem by adding more specific custom paths for python, all the way down to the dir containing my wsgi.py file.
My index.fcgi file was:
...
# Add a custom Python path. (optional)
sys.path.insert(0, "/home/*username*/django")
# Switch to the directory of your project.
...
Now it is:
...
# 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.
...
I assume this is due to the welcome page code being located along a path located nearer the beginning in the list of paths than the admin code is.
As mentioned by @Daniel, mod_wsgi in Apache doesn't pick up code changes by default. However, it can be configured to do so. See:
http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Monitoring_For_Code_Changes
精彩评论