开发者

how to display python list in django template

开发者 https://www.devze.com 2023-01-31 10:15 出处:网络
I am new to python and django. I want to know how can I dispaly python list in django template. The list is a list of days in开发者_StackOverflow weeks e.g day_list = [\'sunday\',\'monday\',\'tuesday\

I am new to python and django. I want to know how can I dispaly python list in django template. The list is a list of days in开发者_StackOverflow weeks e.g day_list = ['sunday','monday','tuesday']


Pass it to the template as a context and then simply iterate over it.

{% for day in day_list %}
    {{ day }}
{% endfor %}

This is the documentation for the for tag. I recommend you go through the Django tutorial, and in part 3 they go over passing stuff to your templates, including iterating over sequences of stuff (like lists).


You need to pass it in the template context.

render_to_response(..., {"day_list": ['sunday','monday','tuesday']} )
0

精彩评论

暂无评论...
验证码 换一张
取 消