[Answer]-Bootstrap select and django template

0👍

Finally, I found a solution! As catavaran said, that was not a Django dev server issue. I just misunderstood, how to correctly use ‘render’ and ‘value’ methods. In my case solution was simple:

$('.selectpicker').val('{{ request.user.profile.bd_month }}');
$('.selectpicker').selectpicker('render');

Thanks catavaran for help!

👤NONAMA

1👍

You should set selected attribute to the selected <option> instead of empty one:

<select id="id_bd_month" name="bd_month" class="selectpicker" ...>
<option value="01">January</option>
<option value="02" selected="selected">February</option>

Or as alternative pass the selected value to the selectpicker() method:

$('.selectpicker').selectpicker('render');
$('.selectpicker').selectpicker('val', '{{ request.user.profile.bd_month}}');

Leave a comment