python - 找不到页面 (404) 请求方法:GET 请求 URL:http://127.0.0.1:8000/hello
问题描述
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
测试应用程序/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>')
卡拉尼/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)
]
卡拉尼/settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'testapp'
]
解决方案
您必须将这些 url 导入到ROOT_URLCONF
您下的变量settings.py
中,例如:
...
ROOT_URLCONF = 'kalani.urls'
...
推荐阅读
- json - 使用 JQ 中更高级别对象的值更新深度嵌套的字段
- orchardcms - Orchard Core CMS - 是否可以获取现有内容项以显示在另一个内容项中?
- mongodb - 如何从数据库查询中获取特定字段?
- javascript - 如何在javascript中增加地图的所有值
- php - Laravel 7找不到范围
- python - 从用户输入手动更新 Dash 表
- prometheus - Grafana仪表板变量:当指标等于一个值时如何提取标签值
- c# - c#带有CspParameters的RSACryptoServiceProvider不能设置keySize
- node.js - CSS和JS文件未在节点js中链接
- kubernetes - 在 GCP 上运行 Kubernetes 集群时可以使用哪些持久卷存储解决方案?