Interesting, Iâm curious if thatâs a recent change in Flask? What version of flask did you install?
Incidentally, @gpkesley the extra space between a function name and the parens isnât a syntax error. It is inconsistent with how everyone else types code but itâll still run. @BennettInHouston should stop adding the space mostly because other people will complain about it, not because itâs an error of any syntax.
Hi Zed, I followed your instructions to a tee and had the same issues regarding the Internal Server Error. Followed @BennettInHouston file structure and worked perfectly.
Just letting you know my issues and what worked for me
(lpthw) 192-168-1-102:gothonweb Michael$ python app.py
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
[2021-02-02 08:54:42,736] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
File "/Users/Michael/.venvs/lpthw/lib/python3.6/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/Users/Michael/.venvs/lpthw/lib/python3.6/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/Michael/.venvs/lpthw/lib/python3.6/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Users/Michael/.venvs/lpthw/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/Users/Michael/.venvs/lpthw/lib/python3.6/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/Michael/.venvs/lpthw/lib/python3.6/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "app.py", line 9, in index
return render_template("index.html", greeting=greeting)
File "/Users/Michael/.venvs/lpthw/lib/python3.6/site-packages/flask/templating.py", line 138, in render_template
ctx.app.jinja_env.get_or_select_template(template_name_or_list),
File "/Users/Michael/.venvs/lpthw/lib/python3.6/site-packages/jinja2/environment.py", line 930, in get_or_select_template
return self.get_template(template_name_or_list, parent, globals)
File "/Users/Michael/.venvs/lpthw/lib/python3.6/site-packages/jinja2/environment.py", line 883, in get_template
return self._load_template(name, self.make_globals(globals))
File "/Users/Michael/.venvs/lpthw/lib/python3.6/site-packages/jinja2/environment.py", line 857, in _load_template
template = self.loader.load(self, name, globals)
File "/Users/Michael/.venvs/lpthw/lib/python3.6/site-packages/jinja2/loaders.py", line 115, in load
source, filename, uptodate = self.get_source(environment, name)
File "/Users/Michael/.venvs/lpthw/lib/python3.6/site-packages/flask/templating.py", line 60, in get_source
return self._get_source_fast(environment, template)
File "/Users/Michael/.venvs/lpthw/lib/python3.6/site-packages/flask/templating.py", line 89, in _get_source_fast
raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: index.html
127.0.0.1 - - [02/Feb/2021 08:54:42] "GET / HTTP/1.1" 500 -
It looks like your index.html file is not available. Look at your code and see where it should be, then make sure that file is in the right template location.
Any idea what I am doing wrong? I have a feeling it has something to with the directories again, but I have been playing around with it for a while and cannot seem to figure it out.
For that you need to setup a static/ directory that flask serves, put the static .css and other files in there (images, javascript), and then make your URLs match that. You can see the docs here:
And the sample app here:
And if you google: âflask static filesâ or âflask cssâ this will come up.