我完全明白你的问题,要用纯烧瓶来达到这个目的。
但几个月前我也和你一样。而经过大量的研究和奇思妙想,我发现,实现它不仅会费尽心思,而且会费时费力,任何微小的改动或调试工作都会把整个事情搞砸。
这是我的表单,使用HTML和Jinja2:
<form method="POST" action="">
{{ form.hidden_tag() }}
<fieldset class="form-group">
<legend class="border-bottom mb-4">XYZ</legend>
<div>
{{ form.standard.label(class="form-control-label") }}
{{ form.standard(class="form-control form-control-lg") }}
</div>
<div>
{{ form.wps.label(class="form-control-label") }}
{{ form.wps(class="form-control form-control-lg") }}
</div>
...
</fieldset>
<div class="form-group">
{{ form.submit(class='btn btn-outline-success') }}
</div>
</form>
此视图称为此窗体:
@app.route("/newqualification/<welder_id>", methods=['GET', 'POST'])
def newqualification(welder_id=None):
form = #passformhere
#writemethod.
return render_template('xyz.html', title='xyz', form=form)
<script>
标签。
<script>
$(document).ready(function(){
$("#standard").change(function(){
var std = $(this).find('option:selected').val(); //capture value from form.
$.getJSON("{{url_for('modifywps')}}",{'std':std}, function(result){ //use captured value to sent to view via a dictionary {'key':val}, via url_for('view_name')
$.each(result, function(i, field){ //value you want will be back here and gone through..
$.each(field, function(j,k){
$("#wps").append('<option value="'+j+'">'+k+'</option>'); // use jQuery to insert it back into the form, via the form name you gave in jinja templating
});
});
});
});
$("#wps").change(function(){
var std = $('#wps').find('option:selected').val(); // capture value from form.
$.getJSON("{{url_for('modifyprocess')}}",{'std':std}, function(result)
$.each(result, function(i, field){
$.each(field, function(j,k){
$("#processes").append('<option value="'+j+'">'+k+'</option>');
});
});
});
});
</script>
使用jQuery和
getJSON()
方法,我可以向此视图发送请求:
@app.route("/modifywps", methods=['POST', 'GET'])
def modifywps():
application_standard_id = request.args.get('std') # gets value from the getJson()
# process it however you want..
return #whatever you want.
getJSON()
直接插入表格!!
经过大量的研究,我找到了最简单的方法来做你想做的事情,就是通过jQuery。
学习
getJSON()
post()
方法在jQuery中,将其合并到HTML中,您就得到了答案。
jsonify()
我相信您可以通过
import json
将列表馈送到
jsonify()
getJSON()
你曾经发送数据。