I have written an app in flask which return list of values to html page and that values I passed to a variable in HTML to call java script function.
(我在flask中编写了一个应用程序,该应用程序将值列表返回到html页面,并且将值传递给HTML中的变量以调用Java脚本函数。)
I tried to execute below code but it showing an error message:
(我尝试执行以下代码,但显示错误消息:)
jinja2.exceptions.UndefinedError
jinja2.exceptions.UndefinedError: 'jsonfile' is undefined
File "C:NGConf-Explorermyprojectemplatesindex.html", line 27, in top-level template code
JSONTREEVIEWER.processJSONTree('{{ url_for('static', filename=[jsonfile[0]])}}','0');
File "C:NGConf-Explorermyprojectvenvlibsite-packagesjinja2environment.py", line 411, in getitem
return obj[argument]
jinja2.exceptions.UndefinedError: 'jsonfile' is undefined
FLASK code:
(FLASK代码:)
@app.route('/')
def home():
if not session.get('logged_in'):
return render_template('login.html')
else:
# Open a file
#path= r"C:NGConf-Explorermyprojectyang\"
#dirs = os.listdir(path)
filename = []
dirs = ['Pyang_output.json2', 'Pyang_output.json3']
for file in dirs:
#filename.append(file).as_uri()
#print(filename)
filename.append(file)
return render_template('index.html',filename=filename)
HTML code:
(HTML代码:)
<script type="text/javascript">
$(function(){
JSONTREEVIEWER.init();
file = {{filename|tojson}};
var i;
for (i = 0; i < file.length; i++) {
JSONTREEVIEWER.processJSONTree('{{ url_for('static',
filename=file[0])}}','0');
}
ask by hemant belwal translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…