-1

How to set deafult value of django form select field in template?

How to set deafult value of django form select field in template?

tima
  • 3
  • 1

1 Answers1

0

Simply you can do this way:

<select id="ip_addr">
    {% for host in hosts %}
        <option value="{{ host.ipaddress }}" {% if forloop.first %}selected{% endif %}>{{ host.ipaddress }}</option> #here default value will be first value from for loop
    {% endfor %}
</select>

This is the way you can do

Manoj Tolagekar
  • 1,816
  • 2
  • 5
  • 22