我试图在django模板中显示过滤的对象,但是由于某种原因,我不知道django不会显示它们。
我有一个类似的视图函数和模板,它们确实可以显示,但是此特定函数却没有。
这是我的urls.py,html模板和views.py文件:
负责网址的views.py函数:
def game_category_list(request, slug):
template = 'game_category_list.html'
category = get_object_or_404(gameIdentifier, game_choice=slug)
post = gameIdentifier.objects.filter(game_choice=category)
context = {
'category':category,
'post':post,
}
return render(request, template, context)
Url.py(其中包含另一个称为的url,它的确显示了与该条相关的所有帖子。
urlpatterns = [
path('', views.index, name='index'),
path('categories/<slug:slug>', views.game_category_list, name='game_category_list'),
path('<slug:slug>/', views.category_detail, name='game_category'),
]
这是game_category_list函数的html文件:
{% extends 'base_layout.html' %}
{% block content %}
<div class='gamecategories'>
{% for game in post %}
<div class='gamecategoriesdisplay'>
<h1>{{game.game_name}}</h1>
</div>
{% endfor %}
</div>
{% endblock %}
我不知道为什么这行不通。任何帮助将不胜感激。