Когда я запускаю свое приложение Flask напрямую с Python (режим разработки?), Все работает нормально, поэтому папка с шаблонами находится в нужном месте.Когда я запускаю его через Gunicorn, он постоянно не может найти папку с моими шаблонами и, следовательно, необходимые HTML-файлы.Я пробовал множество вещей, таких как изменение переменной template_folder
и путь, который передается в render_template()
- ни один из них не оказал никакого влияния.
Я запускаю gunicorn с gunicorn -b 0.0.0.0:80 wsgi
(он все еще не 'работает без wsgi), и все запускается нормально.
Терминал:
root@vps621912:/home/websites/test2# source test2/bin/activate
(test2) root@vps621912:/home/websites/test2# gunicorn -b 0.0.0.0:80 server:app
[2018-12-21 18:13:55 +0000] [30377] [INFO] Starting gunicorn 19.9.0
[2018-12-21 18:13:55 +0000] [30377] [INFO] Listening at: http://0.0.0.0:80 (30377)
[2018-12-21 18:13:55 +0000] [30377] [INFO] Using worker: sync
[2018-12-21 18:13:55 +0000] [30381] [INFO] Booting worker with pid: 30381
[2018-12-21 18:14:00,240] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
File "/home/websites/test2/test2/local/lib/python2.7/site-packages/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "/home/websites/test2/test2/local/lib/python2.7/site-packages/flask/app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/websites/test2/test2/local/lib/python2.7/site-packages/flask/app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/websites/test2/test2/local/lib/python2.7/site-packages/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "/home/websites/test2/test2/local/lib/python2.7/site-packages/flask/app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/websites/test2/server.py", line 10, in home
return render_template('home.html')
File "/home/websites/test2/test2/local/lib/python2.7/site-packages/flask/templating.py", line 134, in render_template
return _render(ctx.app.jinja_env.get_or_select_template(template_name_or_list),
File "/home/websites/test2/test2/local/lib/python2.7/site-packages/jinja2/environment.py", line 869, in get_or_select_template
return self.get_template(template_name_or_list, parent, globals)
File "/home/websites/test2/test2/local/lib/python2.7/site-packages/jinja2/environment.py", line 830, in get_template
return self._load_template(name, self.make_globals(globals))
File "/home/websites/test2/test2/local/lib/python2.7/site-packages/jinja2/environment.py", line 804, in _load_template
template = self.loader.load(self, name, globals)
File "/home/websites/test2/test2/local/lib/python2.7/site-packages/jinja2/loaders.py", line 113, in load
source, filename, uptodate = self.get_source(environment, name)
File "/home/websites/test2/test2/local/lib/python2.7/site-packages/flask/templating.py", line 58, in get_source
return self._get_source_fast(environment, template)
File "/home/websites/test2/test2/local/lib/python2.7/site-packages/flask/templating.py", line 86, in _get_source_fast
raise TemplateNotFound(template)
TemplateNotFound: home.html
Код:
from flask import Flask, render_template
app = Flask('__main__', template_folder='../../')
@app.route('/')
def home():
# return "<h1>test2 - server.py - raw return</h1>"
return render_template('home.html')
# return app.root_path
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)
Любая помощь приветствуется.