Python Forum
show csv file in flask template.html
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
show csv file in flask template.html
#6
(Nov-12-2017, 11:11 AM)snippsat Wrote:
Quote:but it just created a new html page, that also didn't really work cause I can't open it in flask server.
What I wanted to do is to show the csv table in index.html template
The option here is to use Jupyter Notebook,
Notebooks can be shared for free without using a server examples here.
 
Quote:how to send the "dataset.html" content to "index.html"??
I don't know how to use jinja, I'm really new to python programming
Jinja is build into Flask,as it's made bye same author.
It's a way for getting stuff from a Flask server and out to client side(browser).

Here is the setup,
now have control over where in page it should be and size/color and more though CSS.

Folder setup:
tab_test\
  |-- app.py
  |-- email.csv
  templates\
    |-- index.html
  static\
    css\
      |-- style.css
app.py:
from flask import Flask, render_template
import tablib
import os

app = Flask (__name__)
dataset = tablib.Dataset()
with open(os.path.join(os.path.dirname(__file__),'email.csv')) as f:
    dataset.csv = f.read()

@app.route("/")
def index():
    data = dataset.html
    #return dataset.html
    return render_template('index.html', data=data)

if __name__ == "__main__":
    app.run()
index.html:
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <link rel=stylesheet type=text/css href="{{ url_for('static', filename='css/style.css') }}"/>
  <title>Show CSV</title>
</head>
<body>
  <div class="table">
    {% block body %}
    {{ data|safe }}
    {% endblock %}  
  </div>
</body>
</html>
style.css:
.table {       
  position: absolute;
  font-size: 150%;
  width: 480px;
  height: 200px;
  z-index: 15;
  top: 20%;
  left: 50%;
  margin: -100px 0 0 -150px;
  background: rgb(236, 240, 204);
  }

hey, it works.
Thank you so much. Smile
Reply


Messages In This Thread
show csv file in flask template.html - by rr28rizal - Nov-11-2017, 09:17 AM
RE: show csv file in flask template.html - by rr28rizal - Nov-12-2017, 01:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Flask - use bootstrap styles in HTML Krayna 1 1,085 Aug-29-2023, 02:33 PM
Last Post: menator01
Lightbulb Python Obstacles | Kung-Fu | Full File HTML Document Scrape and Store it in MariaDB BrandonKastning 5 2,951 Dec-29-2021, 02:26 AM
Last Post: BrandonKastning
  Show HTML in Python application and handle click SamHobbs 2 2,751 Sep-28-2021, 06:27 PM
Last Post: SamHobbs
  HTML multi select HTML listbox with Flask/Python rfeyer 0 4,682 Mar-14-2021, 12:23 PM
Last Post: rfeyer
Thumbs Up Flask do not accept sub-folder in Template ?! : Solved SpongeB0B 2 3,477 Jan-15-2021, 08:09 AM
Last Post: ndc85430
  API auto-refresh on HTML page using Flask toc 2 11,910 Dec-23-2020, 02:00 PM
Last Post: toc
  how to pass javascript variables to url_for function in a flask template experimental 5 6,450 Oct-29-2020, 03:29 AM
Last Post: universe
  Open and read a tab delimited file from html using python cgi luffy 2 2,701 Aug-24-2020, 06:25 AM
Last Post: luffy
  Flask formatting into HTML engineer_geek 1 2,833 Aug-05-2020, 01:51 AM
Last Post: engineer_geek
  flask How to output stderr and exceptions to log file umen 4 4,831 Jun-20-2020, 06:11 AM
Last Post: umen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020