Closed GoogleCodeExporter closed 9 years ago
There is nowhere near enough information in this report for me to tell you
anything useful. *How* are you trying to use it with Flask? *What* error are
you getting? Unless you show me some code I can't help you at all.
Original comment by luke@maurits.id.au
on 14 Dec 2013 at 11:42
The module is just returning a string without any form of formatting
Original comment by pilotkid2011
on 14 Dec 2013 at 11:44
How are you using it? Show me code.
Original comment by luke@maurits.id.au
on 14 Dec 2013 at 11:53
def hello_admins(username):
from prettytable import *
x = PrettyTable(["Name","Phone","Yardage"])
x.add_row(['John',"7193382296","27"])
x.add_row(['Phil',"7195926682","16"])
x.get_string(attributes = {"class": "foo"})
return render_template("allshooters.html",tbl=x )
Original comment by pilotkid2011
on 14 Dec 2013 at 11:56
Try replacing "get_string" with "get_html_string" and see if that works.
Original comment by luke@maurits.id.au
on 14 Dec 2013 at 11:58
[deleted comment]
I get the same string result... :/
My html code is
{% block contents %}
<p>a</p>
{% for message in get_flashed_messages() %}
<div class = flash>
{{message}}
</div>
{% endfor %}
{{tbl}}
{% endblock %}
Original comment by pilotkid2011
on 15 Dec 2013 at 12:02
Oh! That's because you're just passing the PrettyTable object x to the Flask
rendering system. You need to actually pass the string containing the HTML
code that PrettyTable generates. Get rid of the line:
x.get_string(attributes = {"class": "foo"})
and change the final line to:
return render_template("allshooters.html",tbl=x.get_html_string(attributes =
{"class": "foo"}))
(or, alternatively, store the output of get_html_string in an intermediary
variable and pass that to render_template).
Original comment by luke@maurits.id.au
on 15 Dec 2013 at 12:03
Yay it somewhat worked now I am getting the result as actual html" <table
class="foo"> <tr> <th>Name</th> <th>Phone</th> <th>Yardage</th> </tr> <tr>
<td>John</td> <td>7193382296</td> <td>27</td> </tr> <tr> <td>Phil</td>
<td>7195926682</td> <td>16</td> </tr> </table>" but i can figure it out..
unless you have any quick reconmendations
Original comment by pilotkid2011
on 15 Dec 2013 at 12:06
This is probably something to do with Flask, automatically escaping HTML input
to templates in order to avoid CSS attacks and similar things. I vaguely
recall having to deal with something like that in the past, but I don't know
how to fix it off the top of my head. You should be able to find something in
the Flask docs easily enough.
Original comment by luke@maurits.id.au
on 15 Dec 2013 at 12:08
Ok also may I give you a small piece of constructive criticism with your
tutorial?
Original comment by pilotkid2011
on 15 Dec 2013 at 12:15
Yes, of course! Please do.
Original comment by luke@maurits.id.au
on 15 Dec 2013 at 1:32
There were times when I was reading the tutorial where I was confused on what
you meant I also thought there could be more code but other than that I love
this module I've used it on 3 other projects (I am making my first site now)
but it is a great module it just needs a more coded and better worded tutorial
just to help others
Original comment by pilotkid2011
on 15 Dec 2013 at 4:17
Also I am sorry about this but I cannot figure out the getting the table to
work without getting rid of the style sheet
Original comment by pilotkid2011
on 15 Dec 2013 at 4:27
Try replacing "{{tbl}}" in your template with "{{tbl|safe}}" and see if that
fixes it.
Original comment by luke@maurits.id.au
on 15 Dec 2013 at 4:47
I LOVE YOU!!!!!!
Original comment by pilotkid2011
on 15 Dec 2013 at 4:49
Glad it worked. You should make sure you understand why Flask automatically
escapes HTML by default, and understand when it is and isn't safe to use the
"safe" filter. Maybe read https://en.wikipedia.org/wiki/Cross-site_scripting.
Thanks for your feedback on the tutorial. Next time I update it I'll try
adding some more example code.
Original comment by luke@maurits.id.au
on 15 Dec 2013 at 5:38
Thank you I am am kinda learning the whole flask this but my site is pretty
cool
Original comment by pilotkid2011
on 15 Dec 2013 at 5:39
Original comment by luke@maurits.id.au
on 15 Dec 2013 at 5:56
Original issue reported on code.google.com by
pilotkid2011
on 14 Dec 2013 at 11:24