Show HTML table with Flask and render_template












1















I would like to show a table on a website using Google Cloud SQL and Google App Engine.
I am using Flask and pymysql. To show the result of my query I use the render_template of Flask.



I already found other similar topics here (like Topic: Listing table results to HTML with Flask), but I still get an error when I deploy my app. It seems that the error has to do with the for loop.. The error says "jinja2.exceptions.TemplateSyntaxError: tag name expected".



Here's the full error message I get:



ERROR in app: Exception on /analysis [GET]
Traceback (most recent call last): File "/env/lib/python3.7/site-packages/flask/app.py", line 2292, in wsgi_app response = self.full_dispatch_request()
File "/env/lib/python3.7/site-packages/flask/app.py", line 1815, in full_dispatch_request rv = self.handle_user_exception(e)
File "/env/lib/python3.7/site-packages/flask/app.py", line 1718, in handle_user_exception reraise(exc_type, exc_value, tb)
File "/env/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise raise value
File "/env/lib/python3.7/site-packages/flask/app.py", line 1813, in full_dispatch_request rv = self.dispatch_request()
File "/env/lib/python3.7/site-packages/flask/app.py", line 1799, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args)
File "/srv/main.py", line 61, in analysis return render_template("analysis.html", result = result)
File "/env/lib/python3.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 "/env/lib/python3.7/site-packages/jinja2/environment.py", line 869, in get_or_select_template return self.get_template(template_name_or_list, parent, globals)
File "/env/lib/python3.7/site-packages/jinja2/environment.py", line 830, in get_template return self._load_template(name, self.make_globals(globals))
File "/env/lib/python3.7/site-packages/jinja2/environment.py", line 804, in _load_template template = self.loader.load(self, name, globals)
File "/env/lib/python3.7/site-packages/jinja2/loaders.py", line 125, in load code = environment.compile(source, name, filename)
File "/env/lib/python3.7/site-packages/jinja2/environment.py", line 591, in compile self.handle_exception(exc_info, source_hint=source_hint)
File "/env/lib/python3.7/site-packages/jinja2/environment.py", line 780, in handle_exception reraise(exc_type, exc_value, tb)
File "/env/lib/python3.7/site-packages/jinja2/_compat.py", line 37, in reraise raise value.with_traceback(tb)
File "/srv/templates/analysis.html", line 23, in template <p class="p1"><span class="s1"><span class="Apple-tab-span"> </span>{% </span><span class="s2">for</span><span class="s1"> r </span><span class="s2">in</span><span class="s1"> result %}</span></p>
File "/env/lib/python3.7/site-packages/jinja2/environment.py", line 497, in _parse return Parser(self, source, name, encode_filename(filename)).parse()
File "/env/lib/python3.7/site-packages/jinja2/parser.py", line 901, in parse result = nodes.Template(self.subparse(), lineno=1)
File "/env/lib/python3.7/site-packages/jinja2/parser.py", line 883, in subparse rv = self.parse_statement()
File "/env/lib/python3.7/site-packages/jinja2/parser.py", line 125, in parse_statement self.fail('tag name expected', token.lineno)
File "/env/lib/python3.7/site-packages/jinja2/parser.py", line 59, in fail raise exc(msg, lineno, self.name, self.filename) jinja2.exceptions.TemplateSyntaxError: tag name expected


My Code in main.py:



    import logging
import os
from flask import Flask, render_template
from flask import request
import urllib.request
from urllib.parse import parse_qs, urlparse
import platform
import pymysql
import datetime

db_user = os.environ.get('CLOUD_SQL_USERNAME')
db_password = os.environ.get('CLOUD_SQL_PASSWORD')
db_name = os.environ.get('CLOUD_SQL_DATABASE_NAME')
db_connection_name = os.environ.get('CLOUD_SQL_CONNECTION_NAME')

app = Flask(__name__)

@app.route('/analysis', methods=['GET'])
def analysis():
if os.environ.get('GAE_ENV') == 'standard':
unix_socket = '/cloudsql/{}'.format(db_connection_name)
cnx = pymysql.connect(user=db_user, password=db_password,
unix_socket=unix_socket, db=db_name)
else:
host = '127.0.0.1'
#unix_socket = '/cloudsql/{}'.format(db_connection_name)
cnx = pymysql.connect(user=db_user, password=db_password,
unix_socket=unix_socket, db=db_name)
with cnx.cursor() as cursor:
sql = 'SELECT * FROM content'
cursor.execute(sql)
result = cursor.fetchall()
cnx.close()
return render_template("analysis.html", result = result)

if __name__ == '__main__':
app.run(host='127.0.0.1', port=8080, debug=True)


File analysis.html:



<!doctype html>
<table>
<tr>
  <th>contentID</th>
  <th>timestamp</th> 
  <th>clientID</th>
  <th>content</th>
</tr>
{% for r in result %}
<tr>
  <td>{{ r[0] }}</td>
  <td>{{ r[1] }}</td> 
  <td>{{ r[2] }}</td>
  <td>{{ r[3] }}</td>
</tr>
{% endfor %}
</table>


Do you have any suggestions what I can can change to make it work?

Thanks in advance!










share|improve this question























  • That's a very strange error. Is this definitely representative of your HTML template?

    – roganjosh
    Nov 25 '18 at 9:15






  • 1





    yes, the above code is exactly my html template. In all other comments / topics / tutorials it is described like I did above but it still doesn't work. Do I have to import or install something else?

    – Mari
    Nov 25 '18 at 9:35


















1















I would like to show a table on a website using Google Cloud SQL and Google App Engine.
I am using Flask and pymysql. To show the result of my query I use the render_template of Flask.



I already found other similar topics here (like Topic: Listing table results to HTML with Flask), but I still get an error when I deploy my app. It seems that the error has to do with the for loop.. The error says "jinja2.exceptions.TemplateSyntaxError: tag name expected".



Here's the full error message I get:



ERROR in app: Exception on /analysis [GET]
Traceback (most recent call last): File "/env/lib/python3.7/site-packages/flask/app.py", line 2292, in wsgi_app response = self.full_dispatch_request()
File "/env/lib/python3.7/site-packages/flask/app.py", line 1815, in full_dispatch_request rv = self.handle_user_exception(e)
File "/env/lib/python3.7/site-packages/flask/app.py", line 1718, in handle_user_exception reraise(exc_type, exc_value, tb)
File "/env/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise raise value
File "/env/lib/python3.7/site-packages/flask/app.py", line 1813, in full_dispatch_request rv = self.dispatch_request()
File "/env/lib/python3.7/site-packages/flask/app.py", line 1799, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args)
File "/srv/main.py", line 61, in analysis return render_template("analysis.html", result = result)
File "/env/lib/python3.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 "/env/lib/python3.7/site-packages/jinja2/environment.py", line 869, in get_or_select_template return self.get_template(template_name_or_list, parent, globals)
File "/env/lib/python3.7/site-packages/jinja2/environment.py", line 830, in get_template return self._load_template(name, self.make_globals(globals))
File "/env/lib/python3.7/site-packages/jinja2/environment.py", line 804, in _load_template template = self.loader.load(self, name, globals)
File "/env/lib/python3.7/site-packages/jinja2/loaders.py", line 125, in load code = environment.compile(source, name, filename)
File "/env/lib/python3.7/site-packages/jinja2/environment.py", line 591, in compile self.handle_exception(exc_info, source_hint=source_hint)
File "/env/lib/python3.7/site-packages/jinja2/environment.py", line 780, in handle_exception reraise(exc_type, exc_value, tb)
File "/env/lib/python3.7/site-packages/jinja2/_compat.py", line 37, in reraise raise value.with_traceback(tb)
File "/srv/templates/analysis.html", line 23, in template <p class="p1"><span class="s1"><span class="Apple-tab-span"> </span>{% </span><span class="s2">for</span><span class="s1"> r </span><span class="s2">in</span><span class="s1"> result %}</span></p>
File "/env/lib/python3.7/site-packages/jinja2/environment.py", line 497, in _parse return Parser(self, source, name, encode_filename(filename)).parse()
File "/env/lib/python3.7/site-packages/jinja2/parser.py", line 901, in parse result = nodes.Template(self.subparse(), lineno=1)
File "/env/lib/python3.7/site-packages/jinja2/parser.py", line 883, in subparse rv = self.parse_statement()
File "/env/lib/python3.7/site-packages/jinja2/parser.py", line 125, in parse_statement self.fail('tag name expected', token.lineno)
File "/env/lib/python3.7/site-packages/jinja2/parser.py", line 59, in fail raise exc(msg, lineno, self.name, self.filename) jinja2.exceptions.TemplateSyntaxError: tag name expected


My Code in main.py:



    import logging
import os
from flask import Flask, render_template
from flask import request
import urllib.request
from urllib.parse import parse_qs, urlparse
import platform
import pymysql
import datetime

db_user = os.environ.get('CLOUD_SQL_USERNAME')
db_password = os.environ.get('CLOUD_SQL_PASSWORD')
db_name = os.environ.get('CLOUD_SQL_DATABASE_NAME')
db_connection_name = os.environ.get('CLOUD_SQL_CONNECTION_NAME')

app = Flask(__name__)

@app.route('/analysis', methods=['GET'])
def analysis():
if os.environ.get('GAE_ENV') == 'standard':
unix_socket = '/cloudsql/{}'.format(db_connection_name)
cnx = pymysql.connect(user=db_user, password=db_password,
unix_socket=unix_socket, db=db_name)
else:
host = '127.0.0.1'
#unix_socket = '/cloudsql/{}'.format(db_connection_name)
cnx = pymysql.connect(user=db_user, password=db_password,
unix_socket=unix_socket, db=db_name)
with cnx.cursor() as cursor:
sql = 'SELECT * FROM content'
cursor.execute(sql)
result = cursor.fetchall()
cnx.close()
return render_template("analysis.html", result = result)

if __name__ == '__main__':
app.run(host='127.0.0.1', port=8080, debug=True)


File analysis.html:



<!doctype html>
<table>
<tr>
  <th>contentID</th>
  <th>timestamp</th> 
  <th>clientID</th>
  <th>content</th>
</tr>
{% for r in result %}
<tr>
  <td>{{ r[0] }}</td>
  <td>{{ r[1] }}</td> 
  <td>{{ r[2] }}</td>
  <td>{{ r[3] }}</td>
</tr>
{% endfor %}
</table>


Do you have any suggestions what I can can change to make it work?

Thanks in advance!










share|improve this question























  • That's a very strange error. Is this definitely representative of your HTML template?

    – roganjosh
    Nov 25 '18 at 9:15






  • 1





    yes, the above code is exactly my html template. In all other comments / topics / tutorials it is described like I did above but it still doesn't work. Do I have to import or install something else?

    – Mari
    Nov 25 '18 at 9:35
















1












1








1








I would like to show a table on a website using Google Cloud SQL and Google App Engine.
I am using Flask and pymysql. To show the result of my query I use the render_template of Flask.



I already found other similar topics here (like Topic: Listing table results to HTML with Flask), but I still get an error when I deploy my app. It seems that the error has to do with the for loop.. The error says "jinja2.exceptions.TemplateSyntaxError: tag name expected".



Here's the full error message I get:



ERROR in app: Exception on /analysis [GET]
Traceback (most recent call last): File "/env/lib/python3.7/site-packages/flask/app.py", line 2292, in wsgi_app response = self.full_dispatch_request()
File "/env/lib/python3.7/site-packages/flask/app.py", line 1815, in full_dispatch_request rv = self.handle_user_exception(e)
File "/env/lib/python3.7/site-packages/flask/app.py", line 1718, in handle_user_exception reraise(exc_type, exc_value, tb)
File "/env/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise raise value
File "/env/lib/python3.7/site-packages/flask/app.py", line 1813, in full_dispatch_request rv = self.dispatch_request()
File "/env/lib/python3.7/site-packages/flask/app.py", line 1799, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args)
File "/srv/main.py", line 61, in analysis return render_template("analysis.html", result = result)
File "/env/lib/python3.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 "/env/lib/python3.7/site-packages/jinja2/environment.py", line 869, in get_or_select_template return self.get_template(template_name_or_list, parent, globals)
File "/env/lib/python3.7/site-packages/jinja2/environment.py", line 830, in get_template return self._load_template(name, self.make_globals(globals))
File "/env/lib/python3.7/site-packages/jinja2/environment.py", line 804, in _load_template template = self.loader.load(self, name, globals)
File "/env/lib/python3.7/site-packages/jinja2/loaders.py", line 125, in load code = environment.compile(source, name, filename)
File "/env/lib/python3.7/site-packages/jinja2/environment.py", line 591, in compile self.handle_exception(exc_info, source_hint=source_hint)
File "/env/lib/python3.7/site-packages/jinja2/environment.py", line 780, in handle_exception reraise(exc_type, exc_value, tb)
File "/env/lib/python3.7/site-packages/jinja2/_compat.py", line 37, in reraise raise value.with_traceback(tb)
File "/srv/templates/analysis.html", line 23, in template <p class="p1"><span class="s1"><span class="Apple-tab-span"> </span>{% </span><span class="s2">for</span><span class="s1"> r </span><span class="s2">in</span><span class="s1"> result %}</span></p>
File "/env/lib/python3.7/site-packages/jinja2/environment.py", line 497, in _parse return Parser(self, source, name, encode_filename(filename)).parse()
File "/env/lib/python3.7/site-packages/jinja2/parser.py", line 901, in parse result = nodes.Template(self.subparse(), lineno=1)
File "/env/lib/python3.7/site-packages/jinja2/parser.py", line 883, in subparse rv = self.parse_statement()
File "/env/lib/python3.7/site-packages/jinja2/parser.py", line 125, in parse_statement self.fail('tag name expected', token.lineno)
File "/env/lib/python3.7/site-packages/jinja2/parser.py", line 59, in fail raise exc(msg, lineno, self.name, self.filename) jinja2.exceptions.TemplateSyntaxError: tag name expected


My Code in main.py:



    import logging
import os
from flask import Flask, render_template
from flask import request
import urllib.request
from urllib.parse import parse_qs, urlparse
import platform
import pymysql
import datetime

db_user = os.environ.get('CLOUD_SQL_USERNAME')
db_password = os.environ.get('CLOUD_SQL_PASSWORD')
db_name = os.environ.get('CLOUD_SQL_DATABASE_NAME')
db_connection_name = os.environ.get('CLOUD_SQL_CONNECTION_NAME')

app = Flask(__name__)

@app.route('/analysis', methods=['GET'])
def analysis():
if os.environ.get('GAE_ENV') == 'standard':
unix_socket = '/cloudsql/{}'.format(db_connection_name)
cnx = pymysql.connect(user=db_user, password=db_password,
unix_socket=unix_socket, db=db_name)
else:
host = '127.0.0.1'
#unix_socket = '/cloudsql/{}'.format(db_connection_name)
cnx = pymysql.connect(user=db_user, password=db_password,
unix_socket=unix_socket, db=db_name)
with cnx.cursor() as cursor:
sql = 'SELECT * FROM content'
cursor.execute(sql)
result = cursor.fetchall()
cnx.close()
return render_template("analysis.html", result = result)

if __name__ == '__main__':
app.run(host='127.0.0.1', port=8080, debug=True)


File analysis.html:



<!doctype html>
<table>
<tr>
  <th>contentID</th>
  <th>timestamp</th> 
  <th>clientID</th>
  <th>content</th>
</tr>
{% for r in result %}
<tr>
  <td>{{ r[0] }}</td>
  <td>{{ r[1] }}</td> 
  <td>{{ r[2] }}</td>
  <td>{{ r[3] }}</td>
</tr>
{% endfor %}
</table>


Do you have any suggestions what I can can change to make it work?

Thanks in advance!










share|improve this question














I would like to show a table on a website using Google Cloud SQL and Google App Engine.
I am using Flask and pymysql. To show the result of my query I use the render_template of Flask.



I already found other similar topics here (like Topic: Listing table results to HTML with Flask), but I still get an error when I deploy my app. It seems that the error has to do with the for loop.. The error says "jinja2.exceptions.TemplateSyntaxError: tag name expected".



Here's the full error message I get:



ERROR in app: Exception on /analysis [GET]
Traceback (most recent call last): File "/env/lib/python3.7/site-packages/flask/app.py", line 2292, in wsgi_app response = self.full_dispatch_request()
File "/env/lib/python3.7/site-packages/flask/app.py", line 1815, in full_dispatch_request rv = self.handle_user_exception(e)
File "/env/lib/python3.7/site-packages/flask/app.py", line 1718, in handle_user_exception reraise(exc_type, exc_value, tb)
File "/env/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise raise value
File "/env/lib/python3.7/site-packages/flask/app.py", line 1813, in full_dispatch_request rv = self.dispatch_request()
File "/env/lib/python3.7/site-packages/flask/app.py", line 1799, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args)
File "/srv/main.py", line 61, in analysis return render_template("analysis.html", result = result)
File "/env/lib/python3.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 "/env/lib/python3.7/site-packages/jinja2/environment.py", line 869, in get_or_select_template return self.get_template(template_name_or_list, parent, globals)
File "/env/lib/python3.7/site-packages/jinja2/environment.py", line 830, in get_template return self._load_template(name, self.make_globals(globals))
File "/env/lib/python3.7/site-packages/jinja2/environment.py", line 804, in _load_template template = self.loader.load(self, name, globals)
File "/env/lib/python3.7/site-packages/jinja2/loaders.py", line 125, in load code = environment.compile(source, name, filename)
File "/env/lib/python3.7/site-packages/jinja2/environment.py", line 591, in compile self.handle_exception(exc_info, source_hint=source_hint)
File "/env/lib/python3.7/site-packages/jinja2/environment.py", line 780, in handle_exception reraise(exc_type, exc_value, tb)
File "/env/lib/python3.7/site-packages/jinja2/_compat.py", line 37, in reraise raise value.with_traceback(tb)
File "/srv/templates/analysis.html", line 23, in template <p class="p1"><span class="s1"><span class="Apple-tab-span"> </span>{% </span><span class="s2">for</span><span class="s1"> r </span><span class="s2">in</span><span class="s1"> result %}</span></p>
File "/env/lib/python3.7/site-packages/jinja2/environment.py", line 497, in _parse return Parser(self, source, name, encode_filename(filename)).parse()
File "/env/lib/python3.7/site-packages/jinja2/parser.py", line 901, in parse result = nodes.Template(self.subparse(), lineno=1)
File "/env/lib/python3.7/site-packages/jinja2/parser.py", line 883, in subparse rv = self.parse_statement()
File "/env/lib/python3.7/site-packages/jinja2/parser.py", line 125, in parse_statement self.fail('tag name expected', token.lineno)
File "/env/lib/python3.7/site-packages/jinja2/parser.py", line 59, in fail raise exc(msg, lineno, self.name, self.filename) jinja2.exceptions.TemplateSyntaxError: tag name expected


My Code in main.py:



    import logging
import os
from flask import Flask, render_template
from flask import request
import urllib.request
from urllib.parse import parse_qs, urlparse
import platform
import pymysql
import datetime

db_user = os.environ.get('CLOUD_SQL_USERNAME')
db_password = os.environ.get('CLOUD_SQL_PASSWORD')
db_name = os.environ.get('CLOUD_SQL_DATABASE_NAME')
db_connection_name = os.environ.get('CLOUD_SQL_CONNECTION_NAME')

app = Flask(__name__)

@app.route('/analysis', methods=['GET'])
def analysis():
if os.environ.get('GAE_ENV') == 'standard':
unix_socket = '/cloudsql/{}'.format(db_connection_name)
cnx = pymysql.connect(user=db_user, password=db_password,
unix_socket=unix_socket, db=db_name)
else:
host = '127.0.0.1'
#unix_socket = '/cloudsql/{}'.format(db_connection_name)
cnx = pymysql.connect(user=db_user, password=db_password,
unix_socket=unix_socket, db=db_name)
with cnx.cursor() as cursor:
sql = 'SELECT * FROM content'
cursor.execute(sql)
result = cursor.fetchall()
cnx.close()
return render_template("analysis.html", result = result)

if __name__ == '__main__':
app.run(host='127.0.0.1', port=8080, debug=True)


File analysis.html:



<!doctype html>
<table>
<tr>
  <th>contentID</th>
  <th>timestamp</th> 
  <th>clientID</th>
  <th>content</th>
</tr>
{% for r in result %}
<tr>
  <td>{{ r[0] }}</td>
  <td>{{ r[1] }}</td> 
  <td>{{ r[2] }}</td>
  <td>{{ r[3] }}</td>
</tr>
{% endfor %}
</table>


Do you have any suggestions what I can can change to make it work?

Thanks in advance!







python html flask pymysql






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 25 '18 at 9:07









MariMari

82




82













  • That's a very strange error. Is this definitely representative of your HTML template?

    – roganjosh
    Nov 25 '18 at 9:15






  • 1





    yes, the above code is exactly my html template. In all other comments / topics / tutorials it is described like I did above but it still doesn't work. Do I have to import or install something else?

    – Mari
    Nov 25 '18 at 9:35





















  • That's a very strange error. Is this definitely representative of your HTML template?

    – roganjosh
    Nov 25 '18 at 9:15






  • 1





    yes, the above code is exactly my html template. In all other comments / topics / tutorials it is described like I did above but it still doesn't work. Do I have to import or install something else?

    – Mari
    Nov 25 '18 at 9:35



















That's a very strange error. Is this definitely representative of your HTML template?

– roganjosh
Nov 25 '18 at 9:15





That's a very strange error. Is this definitely representative of your HTML template?

– roganjosh
Nov 25 '18 at 9:15




1




1





yes, the above code is exactly my html template. In all other comments / topics / tutorials it is described like I did above but it still doesn't work. Do I have to import or install something else?

– Mari
Nov 25 '18 at 9:35







yes, the above code is exactly my html template. In all other comments / topics / tutorials it is described like I did above but it still doesn't work. Do I have to import or install something else?

– Mari
Nov 25 '18 at 9:35














1 Answer
1






active

oldest

votes


















1














Based on the stack trace, the text editor you're using for analysis.html isn't a plain text editor. It's saving the file in some other format, making it invalid Jinja2 syntax.



So this line that you see in your editor:



{% for r in result %}


Python will see as (based on the stack trace; added some line breaks for clarity):



<p class="p1">
<span class="s1">
<span class="Apple-tab-span">
</span>
{% </span><span class="s2">for</span><span class="s1"> r </span><span class="s2">in</span><span class="s1"> result %}
</span>
</p>


To fix the problem, open the file analysis.html in a plain text editor and edit it as needed.






share|improve this answer



















  • 1





    That was it, thank you so much! I didn't know that the Mac TextEditor changes the code from what I see in the program to something else.

    – Mari
    Nov 25 '18 at 9:50











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53466062%2fshow-html-table-with-flask-and-render-template%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Based on the stack trace, the text editor you're using for analysis.html isn't a plain text editor. It's saving the file in some other format, making it invalid Jinja2 syntax.



So this line that you see in your editor:



{% for r in result %}


Python will see as (based on the stack trace; added some line breaks for clarity):



<p class="p1">
<span class="s1">
<span class="Apple-tab-span">
</span>
{% </span><span class="s2">for</span><span class="s1"> r </span><span class="s2">in</span><span class="s1"> result %}
</span>
</p>


To fix the problem, open the file analysis.html in a plain text editor and edit it as needed.






share|improve this answer



















  • 1





    That was it, thank you so much! I didn't know that the Mac TextEditor changes the code from what I see in the program to something else.

    – Mari
    Nov 25 '18 at 9:50
















1














Based on the stack trace, the text editor you're using for analysis.html isn't a plain text editor. It's saving the file in some other format, making it invalid Jinja2 syntax.



So this line that you see in your editor:



{% for r in result %}


Python will see as (based on the stack trace; added some line breaks for clarity):



<p class="p1">
<span class="s1">
<span class="Apple-tab-span">
</span>
{% </span><span class="s2">for</span><span class="s1"> r </span><span class="s2">in</span><span class="s1"> result %}
</span>
</p>


To fix the problem, open the file analysis.html in a plain text editor and edit it as needed.






share|improve this answer



















  • 1





    That was it, thank you so much! I didn't know that the Mac TextEditor changes the code from what I see in the program to something else.

    – Mari
    Nov 25 '18 at 9:50














1












1








1







Based on the stack trace, the text editor you're using for analysis.html isn't a plain text editor. It's saving the file in some other format, making it invalid Jinja2 syntax.



So this line that you see in your editor:



{% for r in result %}


Python will see as (based on the stack trace; added some line breaks for clarity):



<p class="p1">
<span class="s1">
<span class="Apple-tab-span">
</span>
{% </span><span class="s2">for</span><span class="s1"> r </span><span class="s2">in</span><span class="s1"> result %}
</span>
</p>


To fix the problem, open the file analysis.html in a plain text editor and edit it as needed.






share|improve this answer













Based on the stack trace, the text editor you're using for analysis.html isn't a plain text editor. It's saving the file in some other format, making it invalid Jinja2 syntax.



So this line that you see in your editor:



{% for r in result %}


Python will see as (based on the stack trace; added some line breaks for clarity):



<p class="p1">
<span class="s1">
<span class="Apple-tab-span">
</span>
{% </span><span class="s2">for</span><span class="s1"> r </span><span class="s2">in</span><span class="s1"> result %}
</span>
</p>


To fix the problem, open the file analysis.html in a plain text editor and edit it as needed.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 25 '18 at 9:36









SmiSmi

10.2k74255




10.2k74255








  • 1





    That was it, thank you so much! I didn't know that the Mac TextEditor changes the code from what I see in the program to something else.

    – Mari
    Nov 25 '18 at 9:50














  • 1





    That was it, thank you so much! I didn't know that the Mac TextEditor changes the code from what I see in the program to something else.

    – Mari
    Nov 25 '18 at 9:50








1




1





That was it, thank you so much! I didn't know that the Mac TextEditor changes the code from what I see in the program to something else.

– Mari
Nov 25 '18 at 9:50





That was it, thank you so much! I didn't know that the Mac TextEditor changes the code from what I see in the program to something else.

– Mari
Nov 25 '18 at 9:50


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53466062%2fshow-html-table-with-flask-and-render-template%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Lallio

Unable to find Lightning Node

Futebolista