Django版本= 1.11
Python版本= 3.6.5
kalani是项目文件夹
testapp是应用程序文件夹
我认为我的问题出在urls.py。
错误消息:
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'
]
答案 0 :(得分:0)
您必须将这些网址导入ROOT_URLCONF
下的变量settings.py
中,例如:
...
ROOT_URLCONF = 'kalani.urls'
...