views:

49

answers:

2

I am familiarizing my self with django.

I have succesfully installed and tested a demo site. I now want to switch on the admin module, to see what happens.

This is the steps I took (granted, some were unnecessary, but I just wanted to make sure I was starting from a clean slate):

  1. Edited mysite/settings.py to enable admin
  2. Edited mysite/url.py to enable admin
  3. dropped and recreated my backend db
  4. run ./manage.py syncdb (and responded correctly to the prompts)
  5. started the dev web server (./manange.py runserver)

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?

+6  A: 

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/'

Ashok
+2  A: 

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!

Manoj Govindan