当我点击html上的“viewall”提交按钮时,它会转到“RestInfo url”,并在错误Django处显示NoReverseMatch

2024-10-01 19:32:41 发布

您现在位置:Python中文网/ 问答频道 /正文

模板代码

<a href="{% url 'ViewAll' cust.custId %}" <button class="btn  cart viewall">View All</button></a>
<a href="{% url 'RestInfo' rest.restId cust.custId   %}" style="color: #000000;">RestInfo</button></a>

url.py

path('ViewAll/<str:mycid>',views.ViewAll,name='ViewAll')

path('myRest/<int:myid>/<str:cid>',views.RestInfo,name='RestInfo'),

视图.py

def ViewAll(request,mycid):
print("Welcome",mycid)
rests= Restaurant.objects.all()
return render(request,'viewall.html',{'rests':rests})

def RestInfo(request,myid=None,cid=None):
rests= Restaurant.objects.filter(restId=myid)
return render(request,"restInfo.html",{'rest':rests[0]})

When I Clicked on button in which viewll url is given then it goes to restinfo and shows me noreversematch error


Tags: pyresturlrequestbuttonhrefcustmyid
1条回答
网友
1楼 · 发布于 2024-10-01 19:32:41

在深入研究Django之前,先学习更好的Python及其代码风格。 对于您得到的错误,基本上是将mycid传递给视图,但您没有使用它,因此从url中删除该mycid,并仅使用all/作为路径

相关问题 更多 >

    热门问题