404 error in django when visiting / Runserver returns no errors though

纵饮孤独 提交于 2019-12-02 08:11:38

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/

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)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!