我有一个字典清单。如何使用此列表将此列表传递给javascript函数?
list_of_keys = []
list_of_connections = []
@app.route("/", methods=('GET', 'POST'))
def hello():
form = SignupForm()
val = False
if request.method == 'POST' and form.validate_on_submit():
#print(UPLOADS_PATH)
#print("sakshi")
adlsgraph(str(form.adlsname1.data),str(form.adlsname2.data))
print(list_of_keys)
print(list_of_connections)
lis1 = {"list_of_keys":list_of_keys,
"list_of_connections":list_of_connections}
lis=json.dumps(lis1)
print(lis)
return redirect(url_for('.hello', lis=list_of_keys, _anchor="services"))
return render_template('index.html', form=form, val=val, lis=list_of_keys)
在烧瓶模板中,
{{ lis|tojson|safe }}
输出显示空白列表-
"\"{}\""
答案 0 :(得分:0)
在视图功能hello
中您没有对list_of_keys
做任何事情,这就是为什么它在模板中为空列表的原因。