小编Hob*_*nob的帖子

烧瓶渲染模板

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 静态

模板文件夹

html flask python-2.7

1
推荐指数
1
解决办法
6563
查看次数

标签 统计

flask ×1

html ×1

python-2.7 ×1