2017-03-18 52 views
1

我用燒瓶並試圖顯示我的HTML文件,但是,我總是得到一個404。我的HTML文件已經在我的模板文件夾。這是下面的項目結構:爲什麼render_template沒有找到404?

projectfolder/ 
     app.py 
     templates/ 
      frontend.html 

這是代碼:

import sys 
sys.path.append('C:\Users\Software\Anaconda2\Lib\site-packages') 
from flask import Flask, render_template 

app = Flask(__name__) 

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

@app.route('/') 
def home(): 
    return render_template('frontend.html') 

回答

1

我覺得你把app.run()呼叫太早,我建議你把它移動到文件的末尾。

import sys 
sys.path.append('C:\Users\Software\Anaconda2\Lib\site-packages') 
from flask import Flask, render_template 

app = Flask(__name__) 

@app.route('/') 
def home(): 
    return render_template('frontend.html') 

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

在您的代碼app.run您的任何路線註冊之前執行。

+0

哇,它的工作!非常感謝! – user1234567890