【发布时间】:2021-03-12 22:38:07
【问题描述】:
您好,我正在尝试添加一个名为 localhost:8000/shop 的基本网址
这样当我在我的主页上时,我可以点击一个名为 shop 的链接,它会引导我到 localhost:8000/shop
在我添加的 urls.py 中
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import include, path
from homepage import views
urlpatterns = [
path('' , views.home),
path('admin/', admin.site.urls),
path('reviews/' , include('reviews.urls')),
path('shop/' , include('product.urls')),
]
在我的名为 product 的文件夹中,我有一个 urls.py 文件
from django.urls import include, path
from . import views
urlpatterns = [
path('shop/' , views.shop),
]
在我的产品文件夹中,我有一个 views.py 文件
from django.shortcuts import render
# Create your views here.
def shop(request):
return render(request, 'product/shop.html')
将它链接到我的产品文件夹中的 html 文件.. 当我运行服务器时,我收到此错误消息
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/shop
Using the URLconf defined in yorleico.urls, Django tried these URL patterns, in this order:
admin/
reviews/
shop/
The current path, shop, didn't match any of these.
我做错了什么?!
【问题讨论】:
标签: python django django-views django-templates django-urls