django.urls.exceptions.NoReverseMatch: 找不到“home”的反向解析。'home'不是一个有效的视图函数或模式名称。

3
我有一个问题,我的URL被视为无效的URL。 我的Django应用程序中没有一个URL起作用。 我犯了一个错误,即使用了我用于另一个应用程序的相同秘密密钥。 这是我的错误消息、URL页面和视图的图片。

错误消息

urls.py

views.py

from django.shortcuts import render
from home.models import Products

#This is the store view
def home(request):
    return render(request,'home.html')

#This is the About Us page view
def AboutUs(request):
    return render(request,'AboutUs.html')

#This is the Long Arm Services View
def LongArmServices(request):
    return render(request,'LongArmServices.html')

#This is the product View
def product(request):
    return render(request,'product.html')

urls.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'),
]

1
请包含代码,而不是代码图像:http://idownvotedbecau.se/imageofcode - Willem Van Onsem
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): return render(request,'LongArmServices.html')#这是产品视图 def product(request): return render(request,'product.html') - James Francies
请[编辑]问题。问题出在模板和urls.py的组合上。请参考答案。 - Willem Van Onsem
1个回答

1
你的urls.py指定了一个app_name = 'home',这意味着你需要在视图名称前面添加app_name和冒号(:)作为前缀。因此,你应该将模板中标记的部分重写为:
href="{% url 'home:home' %}"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接