I am familiarizing myself with Django.
I have successfully installed and tested a demo site. I now want to switch on the admin module, to see what happens.
The steps I took (granted, some were unnecessary, but I just wanted to make sure I was starting from a clean slate):
Here is what my mysite/settings.py file looks like (relevant section only)
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',
# The next lines are my models
'mysite.foo',
'mysite.foobar',
)
Here is what my mysite/urls.py file looks like:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Example:
# (r'^mysite/', include('mysite.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/', include(admin.site.urls)),
)
When I browse to the server url , I get this response:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
1. ^admin/doc/
2. ^admin/
The current URL, , didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
What am I doing wrong?
clearly you are not having any url that handles request to 'http://127.0.0.1:8000/'.
To see the admin page visit, 'http://127.0.0.1:8000/admin/'
When you have the admin urls
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
# (r'^admin/', include(admin.site.urls)),
commented and no other urls, django welcome page is shown by default at 'http://127.0.0.1:8000/'
Request URL: http://127.0.0.1:8000/
You are accessing the root URL. However you have no URL configuration that matches this. Your admin app is at http://127.0.0.1:8000/admin/
. Try that instead.
If you want admin app to be accessible at root, you'll have to change your URL mapping as shown below:
urlpatterns = patterns('',
# Uncomment the next line to enable the admin:
(r'^$', include(admin.site.urls)),
)
Keep in mind that this is NOT recommended. You certainly don't want the root URL to point to the admin app!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With