烧瓶渲染模板

Hob*_*nob 1 html flask python-2.7

Flask 的新手并且对 python 有一些经验,当使用 render_template 时,它​​根本不渲染模板,也不会发出任何错误。代码在这里:

from flask import Flask, render_template

app = Flask(__name__, template_folder= "/templates")




@app.route("/")
def index():
        #return("Index str")
    return render_template("index.html")


@app.route("/crawler")
def crawler():
    return("WebCrawler str")
    return render_template("crawler.html")

if __name__ == "__main__":
    app.run()
    app.debug = True
Run Code Online (Sandbox Code Playgroud)

HTML here(相当确定的文件层次结构是正确的)。

<!DOCTYPE html>

<html lang="en">
    <head>
        <link rel="stylesheet" type="text/css" href="{{url_for('static', filename='style.css')}}">
        <meta charset = "utf-8">
        <title> Index</title>
    <head>
    <body>
        <p> This webserver hosts all webapps and will showcase any unfinished applications.
            </p>

        </body>

</html>
Run Code Online (Sandbox Code Playgroud)

根虚拟环境

css 静态

模板文件夹

Ash*_*ira 5

HTML 文件的默认文件夹是模板。因此,在您的python文件所在的位置创建一个名为“templates”的文件夹。将任何 HTML 文件放在该文件夹中