当访问/ Runserver时,django中的404错误不会返回错误 [英] 404 error in django when visiting / Runserver returns no errors though

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

问题描述

当syncdb和runserver在Django中的一切正常工作时,但是当我尝试访问它在 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天全站免登陆