views.py
def fun(request):
obj=place.objects.all( )
return render(request,"index.html",{'results':obj})
def func(request):
obj=blog.objects.all( )
return render(request,"index.html",{'blogresults':obj})
urls.py:
url模式=[路径('',views.fun,name='fun'(,
path('', views.func, name='func')
]
您有相同的视图函数,并且您试图将两者放在一个页面上,因此您不需要两个函数,在这种情况下,如果您想在一个网页上显示位置和博客,您可以尝试以下操作:
view.py
def fun(request):
obj_0 = place.objects.all( )
obj_1 = blog.objects.all( )
return render(request,"index.html",{'results':obj_0, 'blogresults': obj_1})
url.py
urlpatterns = [ path('', views.fun, name='fun')]
将第二个url路径更改为:
path('func/', views.func, name='func')
你可以通过<your_domain>/func/
点击第二条路径
我建议给你的观点起一个有意义的名字,比如:
def place(request):
...
def blog(request):
...