找不到页面(404)请求方法:GET请求URL:http://127.0.0.1:8000/contacts/contact.html

问题描述 投票:0回答:2

我无法将我的index.html页面与contact.html页面连接,它在我尝试时显示了上述错误使用在Website.urls,

中定义的URLconf

Django按照以下顺序尝试了这些URL模式:

admin /

[name ='主页']

联系人/

当前路径,contacts / contact.html,与任何这些都不匹配。

这是我的contacts.urls.py

from django.urls import path
from . import views

urlpatterns = [
    path('Contact', views.contacts, name='contact-us')
]

我的contacts.views.py

from django.shortcuts import render

# Create your views here.

def contacts(Request):
    return render(Request, 'contact.html')

我的website.urls.py

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('',include('Websiteapp.urls')),
    path('Contact/', include('contacts.urls'))
]
python django django-urls
2个回答
0
投票

尝试打开http://127.0.0.1:8000/Contact/当您在urls.py中定义/ Contact /


0
投票

模板应该具有从任何template目录开始的完整路径。

喜欢这样

def contacts(Request):
    return render(Request, 'myappname/contact.html/')

并且模式应该全部为小写,像这样mywebsite.urls

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('',include('Websiteapp.urls')),
    path('contact/', include('contacts.urls'))
]

contacts.urls

from django.urls import path
from . import views

urlpatterns = [
    path('contact', views.contacts, name='contact-us')
]

现在从contact/contact访问它

© www.soinside.com 2019 - 2024. All rights reserved.