找不到页面(404)请求方法:GET请求URL:http://127.0.0.1:8000/hello

时间:2019-03-11 15:34:35

标签: python django

Django版本= 1.11
Python版本= 3.6.5
kalani是项目文件夹
testapp是应用程序文件夹

我认为我的问题出在urls.py。

http://127.0.0.1:8000/hello

错误消息:

 ERROR:

 Page not found (404)
 Request Method:    GET
 Request URL:   http://127.0.0.1:8000/hello
 Using the URLconf defined in kalani.urls, Django tried these URL 
 patterns, in this order:

^admin/
The current path, hello, didn't match any of these.

You're seeing this error because you have DEBUG = True in your Django 
settings file. Change that to False, and Django will display a standard 
404 page

testapp / views.py:

from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def hello(request):
   return HttpResponse('<h1>Hello world</h1>')

kalani / urls.py:

 from django.conf.urls import url
 from django.contrib import admin
 from testapp import views

 urlpatterns = [
     url(r'^admin/', admin.site.urls),
     url(r'^hello/', views.hello)
 ]

kalani / settings.py

INSTALLED_APPS = [
   'django.contrib.admin',
   'django.contrib.auth',
   'django.contrib.contenttypes',
   'django.contrib.sessions',
   'django.contrib.messages',
   'django.contrib.staticfiles',
   'testapp'
]

1 个答案:

答案 0 :(得分:0)

您必须将这些网址导入ROOT_URLCONF下的变量settings.py中,例如:

...
ROOT_URLCONF = 'kalani.urls'
...