How to display python list in django template

I am new to python and django. I want to know how I can display a python list in a django template. A list is a list of days in weeks, for example: day_list = ['sunday', 'monday', 'tuesday']

+7
source share
2 answers

Pass it into the template as context, and then just 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 iterate over material on your templates, including iterating over sequences of things (like lists).

+12
source

You need to pass it in the context of the template.

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

All Articles