打开(url_for('static',filename='bmidata.txt文件')作为f:
上述行导致语法错误(在“as”处标记)。该代码是以下内容的一部分:
@app.route('/display')
def display():
page_info = {
'title':'Assignment Flask',
'heading': 'Python Flask Assignment'
}
filedata = []
with open(url_for('static', filename='bmidata.txt') as f:
for line in f:
str = line
dataarray = str.split(',')
it =iter(dataarray)
name = it.next()
height = it.next()
weight = it.next()
newPerson = Person(name, height,weight)
filedata.append(newPerson)
return render_template('display.html', info = page_info, fileinfo = filedata)
有什么帮助吗
在这一行中:
您缺少一个右括号:
^{pr2}$这就是SyntaxError的原因。在
以这种方式打开文件不起作用,因为
open
不接受URL。如果需要打开静态文件,请使用with app.open_resource('static/bmidata.txt') as f:
或在文件系统上找到该文件的路径。在相关问题 更多 >
编程相关推荐