简体   繁体   English

“未找到 html 模板”错误(VS 代码)

[英]'html template not found' error (VS Code)

I have the following files on VS code and when I try to run them on my browser, it fails to identify that there is any reg.html template at all.我在 VS 代码中有以下文件,当我尝试在我的浏览器上运行它们时,它根本无法识别有任何 reg.html 模板。 What is the issue?问题是什么?

python file蟒蛇文件

from flask import  Flask, 

render_template, flash

app = Flask(__name__)
app.config["SECRET_KEY"] = "asdfghjkl"

@app.route("/")
def form():
    return render_template("reg.html", title = "Form")

if __name__ == "__main__":
    app.run(debug = True)

html file (reg.html) html 文件 (reg.html)

!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login/Signup - ((title)) </title>

<!-- Bootstrap CSS-->
<link rel = "stylesheet" href = "(( url for('static', filename = 'css/bootstrap.min.css)' ))">
<link rel = "stylesheet" href = "(( url for('static', filename = 'css/site.css') ))">
 
</head>
<body>
    <div class = "container">
        <div class = "row">
            <div class = "col-md-5">
                <h1 class = "text-center">Registration form</h1>
        </div>
        <div class = "col-md-2"></div>
        <div class = "col-md-2"></div>
    </div>
</div>

<!-- Javascript -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.js.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src = "((url for ('static', filename = 'js/bootstrap.min.js')))">`</script>`

</body>
</html>

To solve this question, create a folder named templates , which is where Flask looks for templates by default, then put the reg.html in this folder:为了解决这个问题,创建一个名为templates的文件夹,这是 Flask 默认查找模板的地方,然后将 reg.html 放在这个文件夹中:

在此处输入图片说明

start the program and you will observe the results:启动程序,您将观察结果:

在此处输入图片说明

Detailed information about flask, you can refer to Flask Tutorial .关于flask的详细信息,可以参考Flask教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM