Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 烧瓶找不到模板_Python_Python 3.x_Flask - Fatal编程技术网

Python 烧瓶找不到模板

Python 烧瓶找不到模板,python,python-3.x,flask,Python,Python 3.x,Flask,我有python代码,我想要一个html页面来显示: 我返回render_模板('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 /

我有python代码,我想要一个html页面来显示:

我返回render_模板('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)
jinja2.exceptions.TemplateNotFound:index.html
-[29/Feb/2020 20:35:20]“GET/HTTP/1.1”500-
从烧瓶导入烧瓶,渲染\u模板
将RPi.GPIO导入为GPIO
从时间上导入睡眠
GPIO.setmode(GPIO.BOARD)
GPIO.setup(3,GPIO.OUT)
app=烧瓶(“主烧瓶”)
pwm=GPIO.pwm(3,50)
pwm.启动(0)
@应用程序路径(“/”)
def index():
返回渲染模板('index.html')
@应用程序路径(“/switch/”)
def开关(val):
如果val==“开”:
设定角(0)
elif val==“关闭”:
设定角(180)
返回
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
运行(debug=True,host=0.0.0.0')
def设置角度(角度):
占空比=角度/18+2
GPIO.output(3,真)
pwm.ChangeDutyCycle(占空比)
睡眠(1)
GPIO.output(3,False)
pwm.ChangeDutyCycle(0)

是否使用“/templates/index.py”指定文件?如果是这样,python会认为模板目录位于文件系统“/”的根目录,而不是写“templates/index.py”


如果您在Windows上工作,您可能必须将/替换为\,在这种情况下,您应该编写“templates\index.py”。

从您的代码中我可以看到,一切都应该正常工作!但如果不是这样,合理的答案是你可能正在使用一个损坏/篡改过的flask版本,或者你一定是误读了什么。希望这能澄清问题

设置
app.config['EXPLAIN\u TEMPLATE\u LOADING']=True
以检查flask在哪里查找模板。上面说什么?