init actual
This commit is contained in:
33
app.py
Normal file
33
app.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import requests
|
||||||
|
from flask import Flask, render_template, jsonify, make_response
|
||||||
|
from weasyprint import HTML
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
@app.route('/report')
|
||||||
|
def report():
|
||||||
|
# Prepare graph data
|
||||||
|
graph_data = [
|
||||||
|
{
|
||||||
|
'x': [1, 2, 3],
|
||||||
|
'y': [10, 20, 30],
|
||||||
|
'type': 'scatter'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
return render_template('report.html', graph_data=jsonify(graph_data))
|
||||||
|
|
||||||
|
def get_data():
|
||||||
|
response = requests.get('https://api.example.com/data')
|
||||||
|
return response.json()
|
||||||
|
|
||||||
|
@app.route('/download-pdf')
|
||||||
|
def download_pdf():
|
||||||
|
html = render_template('report.html')
|
||||||
|
pdf = HTML(string=html).write_pdf()
|
||||||
|
response = make_response(pdf)
|
||||||
|
response.headers['Content-Type'] = 'application/pdf'
|
||||||
|
response.headers['Content-Disposition'] = 'inline; filename=report.pdf'
|
||||||
|
return response
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.run(debug=True)
|
||||||
4
requirements.txt
Normal file
4
requirements.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
flask
|
||||||
|
requests
|
||||||
|
weasyprint
|
||||||
|
plotly
|
||||||
29
templates/report.html
Normal file
29
templates/report.html
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<div id="graph"></div>
|
||||||
|
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
|
||||||
|
<script>
|
||||||
|
const data = {{ graph_data | safe }};
|
||||||
|
Plotly.newPlot('graph', data);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Header 1</th>
|
||||||
|
<th>Header 2</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for row in table_data %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ row[0] }}</td>
|
||||||
|
<td>{{ row[1] }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<form method="POST" action="/submit">
|
||||||
|
<label for="data">Enter Data:</label>
|
||||||
|
<input type="text" id="data" name="data">
|
||||||
|
<button type="submit">Submit</button>
|
||||||
|
</form>
|
||||||
Reference in New Issue
Block a user