2015-04-05 169 views
-3
File "/usr/local/lib/python2.7/dist-packages/flask/templating.py", line 64, in get_source 
    raise TemplateNotFound(template) 
TemplateNotFound: hello.html 

腳本app.py的:錯誤TemplateNotFound:從燒瓶hello.html的

from flask import Flask 
from flask import request 
from flask import render_template 

APP = Flask(_name__) 

@APP.route('/') 
def hello(): 
     return render_template('hello.html') 

if _name__ == '_main__': 
    APP.debug=True 
    APP.run() 

我的目錄結構:

app/ 
├── app.py 
├── app.py~ 
├── static 
│   └── style.css 
└── template 
     ├── hello.html 
     └── hello.html~ 
+0

只需回溯告訴我們絕對沒有。你使用什麼代碼?文件位於何處?你的目錄設置是什麼樣的? – 2015-04-05 15:06:34

+0

腳本app.py的: 從燒瓶導入請求燒瓶進口燒瓶 從燒瓶進口render_template APP =燒瓶(_name__) @ APP.route( '/') DEF你好() : 回報render_template( 'hello.html的') 如果_name__ == '_main__': APP.debug =真 APP.run() 而hello.html的: <!DOCTYPE HTML> <元的charset = 「utf-8」/> 你好 你好 – kaio 2015-04-05 15:22:53

+0

那麼'app.py'位於哪裏? 「hello.html」文件位於何處? – 2015-04-05 15:25:12

回答

3

默認的模板目錄名是templates,複數。最後您錯過了s

另外,告訴瓶來看看不同的目錄名:

APP = Flask(_name__, template_folder='template') 
+0

@kaio:您的測試代碼+目錄名稱更改適用於我。你重新啓動了服務器嗎? – 2015-04-05 15:43:03

+0

謝謝當我重新啓動它的工作服務器:)非常感謝 – kaio 2015-04-05 15:46:07