I’m working on a Flask application where users can schedule appointments. In my application, I have a form where users can select a department and then choose a doctor from that department. How do I load doctors dynamically.
hasta_randevual.html
HTML File:
<form action="/randevual/{{ hasta_id }}" method="POST">
<label for="department">Bölüm:</label>
<select id="department" name="department" required>
<option value="" disabled selected hidden>Bölüm Seçiniz</option>
<option value="Genel Cerrahi">Genel Cerrahi</option>
<option value="Kardiyoloji">Kardiyoloji</option>
<!-- Other department options -->
</select>
<label for="doctor">Doktor:</label>
<select id="doctor" name="doctor" required>
{% for doktor in doktorlar %}
<option value="{{ doktor[0] }}">{{ doktor[1] }}</option>
{% endfor %}
</select>
<button type="submit">Randevu Al</button>
</form>
app.py
Python File:
@app.route("/randevual/<hasta_id>")
def randevu_al(hasta_id):
doktorlar=[]
bolum_sec = request.form.get('department')
if request.method == "POST":
if bolum_sec:
doktorlar = Doktor.doktor_bolgoster(bolum_sec)
return render_template("hasta_randevual.html", hasta_id=hasta_id, doktorlar = doktorlar)