python - simple rendering logic for selected fields -


i rendering page setting window.location.href to: /edit_page/?id=user_id in 1 of page , in views.py have this:

id = request.get.get('id')  users = user.objects.all() return render_to_response("index.html",{'id':id,'users':users},context_instance=requestcontext(request)) 

and in index.html, have select field options users being rendered server see in dict, select field per default not selected.

the id have in hand id of user selected edited in page, how can set option selected user id equal id "in left hand".

hope, explained want.

<select> {% user in users %} {% if id == user.id %}<option selected>{% else %}<option>{% endif %}{{ user.first_name }}</option> {% endfor %} </select> 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -