Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Page not found 404 on Django site?

I'm following the tutorial on Django's site to create a simple poll app. However, Django is unable to resolve "//127.0.0.1:8000/polls" , even though I've defined the regex in mySite/urls.py. I'm doing this in a virtualenv, with the latest Django (1.7) installed.

mySite/urls.py:

from django.conf.urls import patterns, include, url from django.contrib import admin  urlpatterns = patterns('', url(r'^admin/', include(admin.site.urls)), url(r'^polls/', include('polls.urls')), ) 

mySite/polls/urls.py:

from django.conf.urls import patterns, url from polls import views  urlpatterns = patterns('', url(r'^$', views.index, name='index'),  ) 

mySite/polls/views.py:

from django.shortcuts import render from django.http import HttpResponse def index(request):     return HttpResponse("Hello, world. You're at the polls index.") 

mySite/settings.py:

 ...  INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'polls',  )    ....  ROOT_URLCONF = 'mySite.urls' 

The error I'm getting:

Using the URLconf defined in mySite.urls, Django tried these URL patterns, in this order: ^admin/   The current URL, polls, didn't match any of these. 
like image 208
jerryh91 Avatar asked Sep 08 '14 01:09

jerryh91


People also ask

What is a 404 error Django?

The 404 error is raised when the URL called upon doesn't exist or has not been defined yet. This is commonly referred to as Page does not exist error. To handle requests from the undefined URLs in a website an error page is created.

Does not exist exception Django?

The DoesNotExist exception is raised when an object is not found for the given parameters of a query. Django provides a DoesNotExist exception as an attribute of each model class to identify the class of object that could not be found and to allow you to catch a particular model class with try/except.

What is internal server error in Django?

When DEBUG is False , Django will email the users listed in the ADMINS setting whenever your code raises an unhandled exception and results in an internal server error (strictly speaking, for any response with an HTTP status code of 500 or greater).


1 Answers

I had the same problem.

It turns out I was confused because of the multiple directories named "mysite".

I wrongly created a urls.py file in the root "mysite" directory (which contains "manage.py"), then pasted in the code from the website.

To correct it I deleted this file, went into the mysite/mysite directory (which contains "settings.py"), modified the existing "urls.py" file, and replaced the code with the tutorial code.

In a nutshell, make sure your urls.py file is in the right directory.

like image 62
ZakJ Avatar answered Oct 08 '22 13:10

ZakJ