Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x django.url.exceptions.NoReverseMatch:与#x27相反;主页';没有找到';主页';不是有效的视图函数或模式名称_Python 3.x_Django - Fatal编程技术网

Python 3.x django.url.exceptions.NoReverseMatch:与#x27相反;主页';没有找到';主页';不是有效的视图函数或模式名称

Python 3.x django.url.exceptions.NoReverseMatch:与#x27相反;主页';没有找到';主页';不是有效的视图函数或模式名称,python-3.x,django,Python 3.x,Django,我的url被视为无效url时出现问题。我的所有URL都不能用于Django应用程序。我犯了一个错误,使用了与另一个应用程序相同的密钥。下面是我的错误消息、url页面和我的视图的图片 URL.py: from django.urls import path from . import views from django.http import HttpResponse app_name='home' urlpatterns = [ path('',views.home,name

我的url被视为无效url时出现问题。我的所有URL都不能用于Django应用程序。我犯了一个错误,使用了与另一个应用程序相同的密钥。下面是我的错误消息、url页面和我的视图的图片

URL.py:

from django.urls import path
from . import views
from django.http import HttpResponse


app_name='home'

urlpatterns = [
    path('',views.home,name='home'),
    path('about_us/',views.AboutUs,name='AboutUs'),        path('long_arm_services/',views.LongArmServices,name='LongArmServices'),
    path('product/',views.product,name='product'),
]

您的
url.py
指定一个
app\u name='home'
,这意味着您需要在视图名称前面加上
app\u name
和冒号(
)。因此,您应该将模板中标记的部分重写为:

href="{% url 'home:home' %}"

href=“{%url'home:home%}”
请包含代码,而不是代码的图像:views.py:from django.shortcuts import render from home.models import Products#这是商店视图def home(request):return render(request,'home.html')#这是关于我们的页面视图def AboutUs(request):return render(request,'AboutUs.html'))#这是长臂服务视图def LongArmServices(request):返回呈现(request,'LongArmServices.html')#这是产品视图def product(request):返回呈现(request,'product.html')请回答问题。问题是模板和
url.py
的组合。看看答案。谢谢你,威廉!
href="{% url 'home:home' %}"