我的代码:
do_nomor = request.args.get('do_nomor', '')
bjdt_no_urut = request.args.get('bjdt_no_urut', '')
try:
SQL = """ SELECT
bjdt_id,
do_nomor,
to_char(do_tgl, 'DD/MM/YYYY' ) as do_tgl,
bjdt_no_urut,
bjqc_nomor,
to_char(bjqc_tgl_buat, 'DD/MM/YYYY' ) as bjqc_tgl_buat,
pelanggan_nama,
pry_nama,
to_char(tgl_rencana_test, 'DD/MM/YYYY' ) as tgl_rencana_test
from v_bendauji_detil where
bjdt_tgl_test is null and
do_nomor = %s
and bjdt_no_urut not in (%s)
ORDER BY bjdt_no_urut ASC limit 10;
"""
conn_string = "dbname='api_rc_38' user='appusr' host='localhost' password='1' port='8765' "
conn = psycopg2.connect(conn_string)
cur = conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
data = ( do_nomor, bjdt_no_urut, )
cur.execute(SQL, data)
rows = cur.fetchone()
cur.close()
conn.close()
json_data = json.dumps(rows)
return json_data
如何在GET方法上使用flask将字符中的变量传递给url? 像这个例子:
http://localhost:5000/bendauji?do_nomor=DOCKET/ICN/05-2017/5175&bjdt_no_urut=('5','6','7',)*
答案 0 :(得分:0)
您可以使用此格式的网址http://localhost:5000/bendauji?do_nomor=DOCKET/ICN/05-2017/5175&bjdt_no_urut=5&bjdt_no_urut=6&bjdt_no_urut=7
获取bjdt_no_urut
使用request.args.getlist('bjdt_no_urut', None)
的值列表。