答案 0 :(得分:0)
注意:我认为问题是你没有在select标签中定义'name'属性。你应该在标签选择中使用属性'name',因为,这是使用字典POST的名称。另外,我建议使用django-crispy-forms
selectinterest.html
<div class="container">
<h1>Change Primary Interest</h1>
<form action="{% url 'myapp:select_discipline' %}" method="POST" id="interest-select">
{% csrf_token %}
<select id="id_interest" name="interest">
<option disabled selected> -- select an option -- </option>
{% for i in interests %}
<option value={{i.id}}>{{i.name}}</option>
{% endfor %}
</select>
<input type="submit" value="Load Disciplines"/>
</form>
</div>
views.py
@login_required
def select_discipline(request):
if request.method == 'POST':
interest = request.POST.get('interest')
context = RequestContext(request)
interests = Interest.objects.order_by('name')
disciplines = Discipline.objects.filter(parentInterest=interest)
return render(
'selectdiscipline.html',
{
'interest': interest,
'interests': interests,
'disciplines': disciplines
},
context
)