Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to display python list in django template

Tags:

python

django

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 weeks e.g day_list = ['sunday','monday','tuesday']

like image 752
hsinxh Avatar asked Dec 21 '10 14:12

hsinxh


People also ask

Can I use filter () in Django template?

Django Template Engine provides filters which are used to transform the values of variables;es and tag arguments. We have already discussed major Django Template Tags. Tags can't modify value of a variable whereas filters can be used for incrementing value of a variable or modifying it to one's own need.

What does {% %} mean in Django?

{% %} and {{ }} are part of Django templating language. They are used to pass the variables from views to template. {% %} is basically used when you have an expression and are called tags while {{ }} is used to simply access the variable.

What is Forloop counter in Django?

A for loop is used for iterating over a sequence, like looping over items in an array, a list, or a dictionary.

How do I get templates in Django?

To configure the Django template system, go to the settings.py file and update the DIRS to the path of the templates folder. Generally, the templates folder is created and kept in the sample directory where manage.py lives. This templates folder contains all the templates you will create in different Django Apps.


1 Answers

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).

like image 59
Daniel DiPaolo Avatar answered Oct 29 '22 18:10

Daniel DiPaolo