模板代码
<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
在深入研究Django之前,先学习更好的Python及其代码风格。 对于您得到的错误,基本上是将mycid传递给视图,但您没有使用它,因此从url中删除该mycid,并仅使用
all/
作为路径相关问题 更多 >
编程相关推荐