首页 > 解决方案 > 找不到烧瓶模板文件夹

问题描述

我正在尝试部署我的烧瓶应用程序,以便它可以在我的局域网中的任何计算机上使用。但是,当我执行它时,我在 apache2 error.log 文件中收到以下错误: 在此处输入图像描述

我的应用程序的架构如下: 在此处输入图像描述

这是针对__init__.py(python3) 的:

from flask import Flask, redirect, url_for, render_template,request
app = Flask('__name__')
@app.route("/", methods=["POST", "GET"])

def home():
    if request.method == "POST":
        return render_template("index.html")
    else: 
        return render_template("index2.html")
if __name__ == "__main__":
    app.run()

我的代码 index.html 是:

<!DOCTYPE html>
<html>
    <head></head>
    <body>
        <h1>Home Page</h1>
        <form action="#" method="post">
            <input type="submit" name="submit">
        </form>
    </body>

</html>

对于 index2.html,它与 index.html 的代码相同,只是标签 h1 具有不同的内容。

当我在本地(http://127.0.0.1:5000/)执行此操作时,它工作正常。

我正在关注本教程:https ://www.youtube.com/watch?v=YFBRVJPhDGY

知道我可能做错了什么吗?

标签: pythonhtmlpython-3.xflask

解决方案


代替

app = Flask('__name__')

app = Flask(__name__)

Flask 使用包/模块名称来定位模板文件夹。


推荐阅读