新來燒瓶,並有一些python的經驗,當使用render_template時,它不會呈現模板,也不會給出任何錯誤。 代碼這裏:燒瓶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
HTML這裏(很肯定的文件層次是正確的)。
<!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>
最後一個屏幕截圖顯示了main.py所在的文件夾中的模板文件夾。 – Hobnob
你是否試圖通過本地主機訪問該網站?如果是這樣,那麼你需要導入操作系統並具有以下代碼:'if __name__ =='__main__': port = int(os.environ.get('PORT',5000)) app.run(host ='0.0。 0.0',port = port)' –
事實上,我從來沒有想過,我只是現在就測試一下。 – Hobnob