我是Python瓶的初学者。我想为我的学校建立一个独立的下拉列表。用户应该从第一个下拉列表中选择程序类别,他应该在其他下拉列表中得到一个过滤的程序列表。我知道,我应该使用jqueryajax,但我没有做到。你知道吗
这是我的html部分
<form action="{{ url_for('individual') }}" method="post" >
<div class="form-group">
<label for="P_cat">Program Category:</label>
<select class="form-control" id="P_cat" name="P_cat">
{% for d in data[0] %}
<option>{{d.0}}</option>
{% endfor %}
</select>
</div>
<div class="form-group">
<label for="pro">Programs:</label>
<select class="form-control" id="pro" name="pro">
<option>Select</option>
{% for d in data[1] %}
<option>{{d.0}}</option>
{% endfor %}
</select>
</div>
这是我的Python路线
@app.route('/individual/', methods = ['GET','POST'])
def individual():
if request.method == 'GET':
cmd = db.cursor()
cmd.execute("select Group_Name from Groups")
groups = cmd.fetchall()
cmd.close()
cmd = db.cursor()
cmd.execute("select program from program")
programs = cmd.fetchall()
cmd.close()
results = [groups,programs]
return render_template ("individual.html",data = results)
在这个阶段,我可以从数据库中获取数据。现在,我必须根据用户对第一个下拉列表的选择来更新第二个下拉列表。 我必须如何在这里编写jquery来从数据库中获取过滤后的信息? 注意:我没有使用flask-WTF或SQLAlchemy(目前对我来说似乎更复杂)。我有用sql编写存储过程和查询的经验。所以,我更喜欢用那种方法。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐