'Flask jinja2.exceptions.TemplateSyntaxError [closed]
I'm trying to render a template in Flask but am getting the following errors:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/flask/app.py", line 1701, in __call__
return self.wsgi_app(environ, start_response)
File "/Library/Python/2.7/site-packages/flask/app.py", line 1685, in wsgi_app
with self.request_context(environ):
File "/Library/Python/2.7/site-packages/flask/ctx.py", line 274, in __enter__
self.push()
File "/Library/Python/2.7/site-packages/flask/ctx.py", line 221, in push
top.pop()
File "/Library/Python/2.7/site-packages/flask/ctx.py", line 257, in pop
self.app.do_teardown_request(exc)
File "/Library/Python/2.7/site-packages/flask/app.py", line 1587, in do_teardown_request
rv = func(exc)
Not sure what this means, but it looks like it's a framework issue. Does anyone know what I can do to troubleshoot/solve this?
Solution 1:[1]
I think the clue is in the exception it is throwing... probably a syntax error in your template. I would try taking out all {{ }} and {% %} tags and adding them back in one by one.
Solution 2:[2]
I had this error and it turned out to be caused by a misplaced space between % and }
% } instead of %}
Solution 3:[3]
Check all closing curly braces.
Probably a % is missing closing a %} delimiter.
Solution 4:[4]
I had the same issue. Just make sure exactly {% is used with %}, like:
{% block something %}
or
... "{{ url_for(...,x=...) }}"
keep some space to make is clearly visible
Solution 5:[5]
I had the same problem and it was caused by the link tag :
link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css')}}">
where it should be :
href="{{ url_for('static', filename='style.css')}}"
{{ url_for(...) }}
Solution 6:[6]
You may have misplaced space between % and }. try to re-run the code after removing extra space.
Solution 7:[7]
Just do change you are file name (like home.html to xhome.html) save it now change it to the render template function too.
render template("home.html") #initial line
render template("xhome.html") #changed line
Solution 8:[8]
making from { % endfor % } to {% endfor %} corrected the code.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | aychedee |
| Solution 2 | mjiap |
| Solution 3 | Punkman |
| Solution 4 | Angel F Syrus |
| Solution 5 | Black_rose |
| Solution 6 | Prb |
| Solution 7 | double-beep |
| Solution 8 | M Emre Çunku? |
