【发布时间】:2021-05-19 01:36:43
【问题描述】:
我正在尝试从视图-> html 呈现一些对象数据。我已经为其他 Django 项目管理过这个,我有点迷失为什么以下不起作用。非常感谢您的帮助!
我在 http 响应中没有收到任何错误,据我所知,下面应该可以工作。相同的对象显示在后端没有问题,请参阅该视图的最后一个代码 sn-p。
解决了
错字 - 在 html 下方
{% 'for val in context'%}
没有收到来自视图的输入,因为它被称为上下文:在渲染中
{'context:' : objects}
谢谢大家
我的html:
<div id="home_top_left_inner" class="container-fluid">
{% if user.is_authenticated %}
{% for val in context %}
<p class='white_text'>{{ val }}</p>
{% endfor %}
{% endif %}
</div>
观看次数
from api.models import general_employee_data
def index(request):
all_employees = general_employee_data.objects.all()
return render(request, 'index.html', {'context' : all_employees})
如果我在上面的视图中打印,我会收到
<QuerySet [<general_employee_data: chang, ko-lin - portal id: ki5s0r3ab>,
<general_employee_data:
test, test - portal id: 19eohz4gy>]>
【问题讨论】:
标签: django-rest-framework django-views django-templates