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

I get to know Django.

I have successfully installed and tested the demo site. Now I want to enable the admin module to find out what will happen.

The steps I took (provided, some of them are not needed, but I just wanted to make sure that I start from scratch):

  • Edited mysite / settings.py to enable admin
  • Edited mysite / url.py to enable admin
  • dropped and restored my backend db
  • run it. /manage.py syncdb (and answered prompts correctly)
  • started dev web server (./manange.py runningerver)

This is what my mysite / settings.py file looks like (only for the corresponding section)

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', ) 

This 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 look at 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
python django django-models django-admin django-urls
source share
3 answers

it’s clear that you don’t have a URL that handles the request for “http://127.0.0.1:8000/”.

To see a visit to the admin page, 'http://127.0.0.1:8000/admin/'

When you have 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's welcome page is displayed by default at 'http://127.0.0.1:8000/'

+11
source

Request URL: http://127.0.0.1:8000/

You get access to the root URL. However, you do not have a URL configuration that matches this. Your administrator application is located at http://127.0.0.1:8000/admin/ . Try this instead.

If you want the admin application to be accessible in the root directory, you will need to change the URL 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. Of course, you don’t want the root URL pointing to the admin application!

+4
source
  • Using PyCharm 2.7
  • Location: urls.py
  • This line (in urls.py) url (r '^ admin /', include (admin.site.urls)) has been uncommented. Added # and voilà, the page works.
0
source

All Articles