Dav*_*ern 2 html python django json django-templates
我正在尝试将JSON加载到Django模板中,并且进展顺利。但是我绕过它,而在它之前。我想知道是否有什么我可以做的。这是我使用的代码:
json_response = requests.get(endpoint + "appointments?user="+user+"&access_token="+token+"&start="+str(int(timestamp_start))+"&end="+str(int(timestamp_end))+"&valid=true").json()
appointmentsVrijdag = json_response['response']['data']
return render(request, template, {"appointmentsVrijdag": appointmentsVrijdag})
Run Code Online (Sandbox Code Playgroud)
然后,要将其加载到模板中,请使用以下代码:
{% for appointment in appointmentsVrijdag %}
{% if appointment.cancelled != True %}
<tr>
<td>
{{ appointment.teachers }}
{{ appointment.subjects }}
</td>
</tr>
{% endif %}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
我希望得到一些帮助!
假设为appointment.teachers或appointment.subjects为列表,您可以使用内置join过滤器将模板中的各项加入其中:
{{ appointment.teachers|join:", " }}
{{ appointment.subjects|join:", " }}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
598 次 |
| 最近记录: |