django - Django没有在模板中显示查询
问题描述
我正在尝试在我的 django 模板中显示过滤后的对象,但是由于某种原因,我不知道 django 不会显示它们。
我有一个类似的视图函数和模板,它确实显示,但这个特定的函数没有。
这是我的 urls.py、html 模板和 views.py 文件:
负责 url 的 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,它确实显示了与 slug 相关的所有帖子。
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 %}
我不知道为什么这不起作用。任何帮助,将不胜感激。
解决方案
推荐阅读
- r - 为 R 中两个数据帧之间的日期范围内发生的事件创建指标变量
- yii2 - 验证选中的复选框数量
- python - 无法通过 python-requests 访问站点(被阻止?)
- java - 将双精度,双精度转换为双精度 []
- firebase - Firebase 的新版本 onAuthStateChanged -> authStateChanges 0
- sql - SQL - 使用 ORM 时,有时不将数据透视表用于 many_to_many 关系是否有意义?
- html - rotatey() 元素与高级 z-index、safari 上的元素重叠
- python - 在给定的页面范围内弹出数据抓取
- python - 使用 xlsx writer 编写自定义日期格式
- python - 验证 RS256 签名的 JWT