在jinja template flask(python)中将json列表传递到javascript

2024-05-20 13:43:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一本字典的目录。如何使用此列表将此列表传递给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 }}

输出显示空列表-

^{pr2}$

Tags: offormhello列表datareturnvalkeys