TemplateError
Vincent Vande Vyvre
vincent.vande.vyvre at telenet.be
Mon Nov 21 02:29:50 EST 2016
Le 21/11/2016 à 07:22, iivri.andre at gmail.com a écrit :
> THIS error is constantly showing up when I run my python script
> eloiim:build iivri.andre$ python run.py
> * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
> [2016-11-21 01:15:26,561] ERROR in app: Exception on / [GET]
> Traceback (most recent call last):
> File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1988, in wsgi_app
> response = self.full_dispatch_request()
> File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1641, in full_dispatch_request
> rv = self.handle_user_exception(e)
> File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1544, in handle_user_exception
> reraise(exc_type, exc_value, tb)
> File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1639, in full_dispatch_request
> rv = self.dispatch_request()
> File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1625, in dispatch_request
> return self.view_functions[rule.endpoint](**req.view_args)
> File "run.py", line 10, in IsSelf
> return render_template('index.html', author=author, name=name)
> File "/usr/local/lib/python2.7/site-packages/flask/templating.py", line 133, in render_template
> return _render(ctx.app.jinja_env.get_or_select_template(template_name_or_list),
> File "/usr/local/lib/python2.7/site-packages/jinja2/environment.py", line 851, in get_or_select_template
> return self.get_template(template_name_or_list, parent, globals)
> File "/usr/local/lib/python2.7/site-packages/jinja2/environment.py", line 812, in get_template
> return self._load_template(name, self.make_globals(globals))
> File "/usr/local/lib/python2.7/site-packages/jinja2/environment.py", line 774, in _load_template
> cache_key = self.loader.get_source(self, name)[1]
> File "/usr/local/lib/python2.7/site-packages/flask/templating.py", line 57, in get_source
> return self._get_source_fast(environment, template)
> File "/usr/local/lib/python2.7/site-packages/flask/templating.py", line 85, in _get_source_fast
> raise TemplateNotFound(template)
> TemplateNotFound: index.html
>
> THIS is the code
>
> from flask import Flask, render_template
> app = Flask(__name__)
>
> @app.route('/')
> # THE @ is a decorator that is used to 'augment' function definitions
> # Flask uses 'route()' to indicate that if the browser requests the address '/' (the default | home address), then our app shoud 'route' that request to this 'IsSelf' function
> def IsSelf() :
> author = "raphael James "
> name = "Jaden iivii"
> return render_template('index.html', author=author, name=name)
>
> if __name__ == "__main__" :
> app.run()
>
>
> How do I fix this?
Flask don't know where are your templates.
I use this:
WEBDIR = os.path.dirname(os.path.abspath('__files__'))
PAGESDIR = os.path.join(os.path.dirname(WEBDIR), 'somewhere/templates')
STATICDIR = os.path.join(os.path.dirname(WEBDIR), 'somewhere/static')
...
app = Flask(__name__, template_folder=PAGESDIR, static_folder=STATICDIR)
...
--
Vincent V.V.
Oqapy <http://www.oqapy.eu> . python3-exiv2
<http://www.py3exiv2.tuxfamily.org/> . Qarte
<https://launchpad.net/qarte> . PaQager <https://launchpad.net/paqager>
More information about the Python-list
mailing list