Python 烧瓶读数尺
我想我在烧瓶上遗漏了什么。我想阅读我的字典,这是一个静态文件的基本模板,并使它出现与烧瓶。知道我为什么会出错吗?谢谢Python 烧瓶读数尺,python,flask,jinja2,Python,Flask,Jinja2,我想我在烧瓶上遗漏了什么。我想阅读我的字典,这是一个静态文件的基本模板,并使它出现与烧瓶。知道我为什么会出错吗?谢谢 from flask import Flask, render_template app = Flask(__name__) @app.route('/') def main(): return render_template('main.html, switch=switchList') if __name__ == '__main__': app.run
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def main():
return render_template('main.html, switch=switchList')
if __name__ == '__main__':
app.run(debug=True)
这是我的main.html
<body>
{% block content %}
{% for switch in switches %}
Switch Name: {{ switch.name }} <br>
- Serial: {{ switch.serial }} <br>
- Reachable at: {{ switch.ip }} <br>
<br>
{% endfor %}
{% endblock %}
</body>
Jinja将把python对象呈现为html。您的问题是您的字典没有作为python对象加载,因此无法将其提供给您的页面解决方案,加载词典并传递html模板:
...
# Load your dict – be sure to enter the correct path
with open('static/switchList.json', 'r') as f:
switchList = json.loads(f)
@app.route('/')
def main():
return render_template('main.html', switch=switchList)
...
Jinja将把python对象呈现为html。您的问题是您的字典没有作为python对象加载,因此无法将其提供给您的页面解决方案,加载词典并传递html模板:
...
# Load your dict – be sure to enter the correct path
with open('static/switchList.json', 'r') as f:
switchList = json.loads(f)
@app.route('/')
def main():
return render_template('main.html', switch=switchList)
...
假设
switchList
保存了要显示的数据,请更改
return render_template('main.html, switch=switchList')
到
假设
switchList
保存了要显示的数据,请更改
return render_template('main.html, switch=switchList')
到
render_template('main.html,switch=switchList')更改为switches=switchList附加您正在获取的错误将有助于更改获得相同的错误“jinja2.exceptions.TemplateNotFound jinja2.exceptions.TemplateNotFound:main.html,switches=switchList”。另外,如果有必要,我的字典文件是根目录。
return render\u template('main.html,switch=switchList')
。它应该是return render\u template('main.html',switch=switchList)
render\u template('main.html,switch=switchList')更改为switches=switchList附加您正在获得的错误将有用更改,获得相同的错误“jinja2.exceptions.TemplateNotFound jinja2.exceptions.TemplateNotFound:main.html,switches=switchList”。另外,如果有必要,我的字典文件是根目录。return render\u template('main.html,switch=switchList')
。它应该是return render\u template('main.html',switch=switchList)