访问/Runserver 时 Django 中的 404 错误虽然没有返回错误 [英] 404 error in django when visiting / Runserver returns no errors though

查看:58
本文介绍了访问/Runserver 时 Django 中的 404 错误虽然没有返回错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 Django 中使用 syncdb 和 runserver 时一切正常,但是当我尝试访问 http://127.0.0.1:8000/ 上的网页时,它返回 404 错误.

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 (404)
Request Method: GET
Request URL:    http://127.0.0.1:8000/
Using the URLconf defined in MyBlog.urls, Django tried these URL patterns, in this order:
^admin/
The current URL, , didn't match any of these.

奇怪的是,当我访问页面上的 /admin 时,它工作正常.我不明白这里出了什么问题.任何帮助都会很棒!

The strange part is that when I visit /admin on the page it works fine. I dont understand what is failing here. Any help would be awesome!

推荐答案

您需要一个指向主页的 URL 路由.MyBlog.urls 中的 urlpatterns 变量应该有一个像 (r'^$', app.views.show_homepage) 这样的元组对,其中 show_homepage 是一个在 views.py 中定义的函数.有关 URL 调度程序的更多信息,您可以在此处阅读:https://docs.djangoproject.com/en/dev/topics/http/urls/

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/

这篇关于访问/Runserver 时 Django 中的 404 错误虽然没有返回错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆