사용자가 선택한 드롭 다운 필드의 값을 가져 와서 다음 페이지에서 드롭 다운 선택에 따라 일부 프로필 목록을 필터링하고 싶습니다.Django 1.6 : 드롭 다운에서 다른 템플릿 페이지로 값을 전달하는 방법
내 index.html 페이지에서이 작업을했습니다하고 드롭 다운에서 옵션을 선택하도록 싶습니다 제출 히트 페이지를
<div class="form-group">
<form action="/doclistings/" method="post">
<select class="form-control" id="select">
<option><b>Choose a Speciality...</b></option>
<option value ="Dermatologist">Dermatologist</option>
<option value = "Dentist">Dentist</option>
<option value = "ENT">Ear, Nose and Throat (ENT)</option>
<option value = "Opthalmologist">Eye Doctor</option>
<option value = "Psychiatrist">Psychiatrist</option>
<option value = "Orthopedist">Orthopedist</option>
</select>
<span class="input-group-btn">
<button class="btn btn-primary" type="submit" name="submit" id="ss-submit">Find Doctors</button>
</span>
</div>
doclistings.html
을 doclistings.html하는 리디렉션{% for doc in doclist %}
{% if doc.specialization == } # value from the last page
<div class = "doctorrow">
<h2><a href="/docprofile/{{doc.id}}/">{{doc.name}}</a></h2>
<h3> {{doc.specialization}}</h3>
</div>
</div>
{% endfor %}
views.py
def index(request):
if request.method == "POST":
form = DropdownSelectionForm(request.POST)
if form.is_valid():
selection = form.cleaned_data['value']
return HttpResponseRedirect('/doclistings')
else:
form = DropdownSelectionForm()
return render(request, 'meddy1/index.html')
@csrf_exempt
def doclistings(request):
return render(request, 'meddy1/doclistings.html', {'doclist': Doctor.objects.all()})
forms.py
,class DropdownSelectionForm(forms.Form):
selection = forms.CharField()
[양식 마법사] (https://docs.djangoproject.com/en/dev/ref/contrib/formtools/form-wizard/)이 좋은 옵션입니다. –