试试这个:
视图.py
from django.shortcuts import render
def home(request):
context = {
'all_s': ['j1', 'j2', 'j3', 'j4'],
'all_j': ['j2', 'j4']
}
return render(request, 'index.html', context)
索引.html
<html>
<header>
<title></title>
</header>
<body>
<select name="bla" id="" multiple style="width: 200px;">
{% for s in all_s %}
{% if s in all_j %}
<option value="{{ s }}" selected="selected">{{ s }}</option>
{% else %}
<option value="{{ s }}">{{ s }}</option>
{% endif %}
{% endfor %}
</select>
</body>
</html>