【发布时间】:2021-04-29 06:21:01
【问题描述】:
我正在显示一个已保存到数据库的发布表单。我让用户可以选择查看数据库中的值,并让他可以选择编辑它们。但是,它不适用于下拉菜单。我试过写一些东西,但它没有显示正确的值。
请帮忙:(((
这里是sn-p的代码:
<div class="form-group col-md-6">
<label for="industry_type">Industry Type</label>
<select class="form-control" id="industry_type" name="industry_type" selected="
{{ internship.industry_type }}">
{% for ind_type in industry_types %}
<option value="{{ ind_type }}" {% if '{{ ind_type }}' == '{{
internship.industry_type }}' %}selected="selected" {% endif %}>
{{ind_type}}</option>
{% endfor %}
</select>
</div>
views.py
def edit_internship(request, pid):
internship = Internship.objects.get(id=pid)
skills = InternshipSkill.objects.filter(internship=internship)
emp_steps = InternshipEmpStep.objects.filter(internship=internship)
.order_by('emp_step_no')
industry_types = IndustryType.objects.all()
context = {
'industry_types': industry_types,
'internship': internship,
'skills': skills,
'emp_steps': emp_steps,
}
return render(request, 'edit_internship.html', context)
【问题讨论】:
-
嗨 :) 您可以编辑您的问题以提供您的视图的代码(在 views.py 中)吗?很难说出您将哪些信息传递给模板。哪个位没有显示?
-
@TomHamiltonStubber 你好 :) 已发布。实习的行业类型可以是信息技术、银行等。我想在下拉列表中显示从所有类型中选择的行业类型
标签: python html django django-models django-views