8

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']

2 Answers 2

16

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

Sign up to request clarification or add additional context in comments.

1 Comment

what if i just want to print monday??
2

You need to pass it in the template context.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.