提问者:小点点

Django:找不到页面,但显示了路径


我最近开始使用Django,我有点不明白为什么我的services.html页面不能呈现,因为我遵循了与我的主页工作时相同的步骤,但是我一直得到错误,没有任何东西与当前路径匹配。 下面是我的views和urls.py的片段。 我还使用path('',include('affiliate.urls')),将其包含在我的网站urls.py中

Using the URLconf defined in website.urls, Django tried these URL patterns, in this order:

admin/
[name='home']
[name='services']
The current path, services.html, didn't match any of these.
Urls.py

from django.urls import path
from . import views

urlpatterns = [         
    path('', views.home, name="home"),
    path('', views.services, name="services"),

]

Views.py

from django.shortcuts import render

# Create your views here.
def home(request):
    return render(request, 'home.html', {})

def services(request):
    return render(request, 'services.html', {})

共1个答案

匿名用户

按以下方式更改urlpatterns:

urlpatterns = [         
    path('', views.home, name="home"),
    path('services/', views.services, name="services"),

]

现在,当您想要访问services视图时,请确保使用127.0.0.1:8000/services,因为home和services的路径都指向同一个URL。

威廉·威廉·正试图向你解释同样的事情。