我在html
中创建了一个包含templating
和flask
的选项。
我需要完成的是获取option
值并将其放入我的代码中,这是我的html
代码:
<select id="oblast_select" name='areaid'>
<option value="0">0</option>
<option value="5971">value1</option>
<option value="7402">value2</option>
<option value="5219">value3</option>
<option value="4949">value4</option>
<option value="5764">value5</option>
<option value="7412">6</option>
<option value="6217">value7</option>
<option value="6802">value8</option>
<option value="6940">value9</option>
</select>
此处还有我的java
代码,它将发布请求发送到python
文件:
var serviceid = document.getElementById("name_street").value;
var areaid = document.getElementById('oblast_select').value;
$(".btn").addClass("clicked");
$.post(
"/serviceidlookup",
{ serviceid: serviceid },
{ areaid: areaid }
).done(function (reply) {
$(".spinner").css("display", "block");
$('.spinner').fadeOut(5500);
setTimeout(function() {
$('#reply').empty().append(reply).fadeIn(3000);
}, 4000);`enter code here`
});
最后是我的python
文件run.py
:
@app.route('/serviceidlookup', methods=["GET", "POST"])
def serviceidlookup():
reload(sys)
sys.setdefaultencoding("utf-8")
sys.stdout.encoding
serviceid = request.form.get('serviceid')
areaid = request.args.get('areaid')
idarea = str(areaid)
con = psycopg2.connect(**config)
cur = con.cursor()
cur.execute("select ate,ate_type,name_kg,name_ru,name_en,parent from ate_history where ate in (select ate from street_ate where street in (select street from street_history where name_ru = '%s') and parent = %s)" %(serviceid,idarea))
entries = [dict(ate=row[0], ate_type=row[1], name_kg=row[2], name_ru=row[3], name_en=row[4], parent=row[5]) for row in cur.fetchall()]
return render_template('lookup.html', serviceid=serviceid, entries=entries)
运行此代码后,在终端中给出了这个错误:
**LINE 1: ...om street_history where name_ru = 'None') and parent = None)**
事实上,我从我创建的输入字段中获取serviceid值,它没有获得我们的选项中的其他值,例如7402在此部分的查询中:
and parent = %s)"
请任何帮助太过于赞赏!!!!!!!
答案 0 :(得分:0)
你写过
serviceid = request.form.get('serviceid')
areaid = request.form.get('areaid')
尝试更改areaid以匹配serviceid,即
var areaid = document.getElementById('oblast_select').value;
修改:尝试替换
var e = document.getElementById("oblast_select");
var areaid= e.options[e.selectedIndex].value;
用这个..
$.post(
"/serviceidlookup",
{ serviceid: serviceid },
{ areaid: areaid } , function (reply) {
$(".spinner").css("display", "block");
$('.spinner').fadeOut(5500);
setTimeout(function() {
$('#reply').empty().append(reply).fadeIn(3000);
}, 4000);
});
Edit2:将您的jQuery帖子更改为此..
temp=re.findall(r"<li>(\d{4}-\d{2}-\d{2} {\d:]{8}).* - (.*) - GET (.*)<\/li>",html)
for i in temp:
print i
答案 1 :(得分:0)
根据Flask文档 - http://werkzeug.pocoo.org/docs/0.10/datastructures/#werkzeug.datastructures.MultiDict,request.args.get()方法默认只返回第一个元素。要获得使用列表方法所需的所有值; request.args.getlist()。