Created
December 19, 2014 05:50
-
-
Save moqada/b7387465690217e216f7 to your computer and use it in GitHub Desktop.
pygal sample on flask
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import pygal | |
from flask import Flask, Response | |
app = Flask(__name__) | |
@app.route('/') | |
def index(): | |
""" render svg on html """ | |
return """ | |
<html> | |
<body> | |
<h1>hello pygal</h1> | |
<figure> | |
<embed type="image/svg+xml" src="/graph/" /> | |
</figure> | |
</body> | |
</html>' | |
""" | |
@app.route('/graph/') | |
def graph(): | |
""" render svg graph """ | |
bar_chart = pygal.Bar() | |
bar_chart.add('Fibonacci', [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]) | |
return Response(response=bar_chart.render(), content_type='image/svg+xml') | |
if __name__ == '__main__': | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment