Skip to content Skip to sidebar Skip to footer

404 Error In Django When Visiting / Runserver Returns No Errors Though

When I syncdb and runserver everything works correctly in Django, but when I try to visit the webpage that it is on http://127.0.0.1:8000/ it returns a 404 error. Page not found (

Solution 1:

You need an URL route to the homepage. The urlpatterns variable in MyBlog.urls should have a tuple pair like (r'^$', app.views.show_homepage), where show_homepage is a function defined in views.py. For more info about the URL dispatcher, you can read about it here: https://docs.djangoproject.com/en/dev/topics/http/urls/

Solution 2:

Check out chapter 3 of Django's Writing your first Django app tutorial.

In short, you need to specify (in urls.py) which code Django should run for particular URLs; there are no default URLs defined (you'll see a line including the admin URLs in urls.py).

Edit your urls.py so it looks something like

from django.conf.urls import patterns, include, url
from django.views.generic import TemplateView

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    url(r'^$', TemplateView.as_view(template_name="home.html"),
)

(you'll also need to create home.html in one of the directories specified in TEMPLATE_DIRS)

Post a Comment for "404 Error In Django When Visiting / Runserver Returns No Errors Though"