【发布时间】:2020-06-13 14:31:40
【问题描述】:
我有 python 代码,我想显示一个 html 页面:
我收到错误返回 render_template('index.html')
我已尝试指定模板文件夹,但它也不起作用。
我的项目目录:
/api
-- api.py
-- /templates
---- index.html
我也在运行服务器,例如: 烧瓶运行 -h 192.168.x.x -p 8080
jinja2.exceptions.TemplateNotFound: index.html
- - [29/Feb/2020 20:35:20] "GET / HTTP/1.1" 500 -
from flask import Flask, render_template
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BOARD)
GPIO.setup(3, GPIO.OUT)
app = Flask("__main__")
pwm = GPIO.PWM(3, 50)
pwm.start(0)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/switch/<val>')
def switch(val):
if val == "on":
SetAngle(0)
elif val == "off":
SetAngle(180)
return
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')
def SetAngle(angle):
duty = angle / 18 + 2
GPIO.output(3, True)
pwm.ChangeDutyCycle(duty)
sleep(1)
GPIO.output(3, False)
pwm.ChangeDutyCycle(0)
【问题讨论】:
-
设置
app.config['EXPLAIN_TEMPLATE_LOADING'] = True来检查flask 在哪里寻找你的模板。它说什么?
标签: python python-3.x flask