2017-03-18 49 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