1

In a django template I have a <select> element with something like:

<option value="0">0</option>
<option value="10">10</option>
<option value="15">20</option>
<option value="30">30</option>
<option value="45">45</option>
<option value="60">60</option>

It's rather ugly and redundant to list out this big mess, I'd like to do something like :

{% for i in list(0, 10, 20, 30, 45, 60) %}
<option value="{{i}}">{{i}}</option>
{% for %}

I suppose I could just put these variables in a context variable, but I don't want to involve the view here, it seems like the kind of thing that should stay at the template level.

1 Answer 1

1

This is exactly the opposite of what you should be doing in the template. Your forms should be assembled at view level and passed to the template via the context. The template should minimal logic and simple display the content from your view. If you use django's Form and ModelForm classes you can have django do all the work for you

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

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.