我正在尝试将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})
然后,要将其加载到模板中,请使用以下代码:
{% for appointment in appointmentsVrijdag %} {% if appointment.cancelled != True %}{% endif %} {% endfor %} {{ appointment.teachers }} {{ appointment.subjects }}
我希望得到一些帮助!
假设为appointment.teachers
或appointment.subjects
为列表,您可以使用内置join
过滤器将模板中的各项加入其中:
{{ appointment.teachers|join:", " }} {{ appointment.subjects|join:", " }}