I have written a python script that reads a csv file and displays it on a web page. The web page is a simple html.
I am trying to display it with a certain format. I have searched through stackoverflow and found this: Formatting output of CSV file in Python which was helpful.
However, it works fine when using the print
function but when I try to render into my webpage the format is not the same and it also displays only one line of result instead of the whole file.
So how can I have it display on my webpage the same format it displays on the python shell?
Here's what I have so far:
@app.route('/results/view')
def my_results():
with open(str(get_file(filename)), "r") as f:
content = csv.reader(f)
for row in content:
content =(('{:^15} {:^15} {:^20} {:^25}'.format(*row)))
return render_template("results.html",content=content)
if __name__ == '__main__':
app.debug = True #Uncomment to enable debugging
app.run() #Run the Server
results.html
<!DOCTYPE html>
<html>
<head>
<title>My webpage</title>
</head>
<body>
<a>{{ content }}</a>
</body>
</html>
results w/ print
statement instead of 'content='
(what I want)
A B
blue Car
yellow Bike
green Boat
result I am getting with content =
A green B Boat
"`? maybe they are escaped? – fredtantini Aug 03 '17 at 11:41
' just gets printed in between the results. So A
blue
car ... – ana Aug 03 '17 at 11:43