Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django - 404 page displayed for dev web server (http://127.0.0.1:8000/)

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):

  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?

like image 516
skyeagle Avatar asked Oct 08 '10 13:10

skyeagle


2 Answers

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

like image 192
Ashok Avatar answered Sep 28 '22 18:09

Ashok


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!

like image 43
Manoj Govindan Avatar answered Sep 28 '22 17:09

Manoj Govindan