Django: Select option in template

后端 未结 1 1841
囚心锁ツ
囚心锁ツ 2020-12-28 16:50

In my Django template, I am using the list of objects in a drop down menu. I am processing it based on the selection.

The HTML Template:

         


        
相关标签:
1条回答
  • 2020-12-28 17:39

    You'll want to pass the currently selected org into the view, maybe as current_org so that when you're iterating through the orgs you can compare with the current one to determine whether or not to select it, like:

    {% for org in organisation %}
       <option value="{{org.id}}"
           {% if org == current_org %}selected="selected"{% endif %}>
           {{org.name|capfirst}}
       </option>
    {% endfor %}
    
    0 讨论(0)
提交回复
热议问题