我有一个问题想将多个对象发送到模板上的同一页,但发生在/
上的问题NoReverseMatchdef index(request):
boards=Board.objects.all()
categorys=Category.objects.all()
context = {
'boards':boards ,
'categorys':categorys,
}
return render(request,'home.html',context=context)
urlpatterns = [
path('', views.index, name='home'),
path('track/<int:track_id>', views.record_view, name='track1'),
path('boards/<int:id>', views.boards_topic, name='boards_topic'),
]
并尝试反转最后两个网址的顺序并保持问题
urlpatterns = [
path('', views.index, name='home'),
path('', views.category_view, name='home'),
...
]
def index(request):
boards=Board.objects.all()
return render(request,'home.html',{'boards':boards})
def category_view(request):
categorys=Category.objects.all()
return render(request,'home.html',{'categorys':categorys})
什么是解决方案,谢谢