这可能很简单,但我无法理解。我正在学习Django,已安装v3.0.4,无法从应用程序获取URL才能正常工作。
在项目urls.py上,我有以下内容:
Project \ urls.py:
from django.contrib import admin
from django.urls import path
from django.urls import include
from AppTwo import views
urlpatterns = [
path('', views.index, name='index'),
path('', include('AppTwo.urls')),
path('admin/', admin.site.urls),
]
我创建了一个名为“ AppTwo”的应用,并在该应用中包含以下urls.py和views.py:
AppTwo \ urls.py:
from django.urls import path
from . import views
urlpatterns = [
path('/help', views.help, name='help'),
]
AppTwo \ views.py:
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def index(request):
return HttpResponse("<em>My Second App</em>")
def help(request):
return HttpResponse("<em>Help Page!!!</em>")
如果我浏览到http://127.0.0.1:8000/,则索引页面会加载,并且会看到文本“我的第二个应用程序”,正如预期的那样。但是,如果我浏览到http://127.0.0.1:8000/help,则会显示找不到页面404错误。
我也可以浏览至管理页面。到目前为止,这是一个库存项目,创建后我所做的唯一其他更改是安装了“ AppTwo”应用程序的settings.py文件。根据文档,这看起来应该可以工作,那么我在做什么错了?
答案 0 :(得分:0)
是的,知道这很简单。
已更改
path('/help', views.help, name='help'),
收件人:
path('help/', views.help, name='help'),
现在一切都好。