Last active
May 29, 2017 09:02
-
-
Save dungvtdev/82a951a92595bd24209c133a355a68dc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Source https://github.com/rduplain/flask-svg-example/blob/master/app.py | |
import os | |
from flask import Flask, make_response, render_template, request | |
app = Flask(__name__) | |
@app.route('/templated.svg') | |
def templated_svg(): | |
"Example using a template in the templates directory." | |
width = request.args.get('width', '800') | |
height = request.args.get('height', '600') | |
svg = render_template('letters.svg', width=width, height=height) | |
response = make_response(svg) | |
response.content_type = 'image/svg+xml' | |
return response | |
@app.route('/database.svg') | |
def database_svg(): | |
"Example using a string stored somewhere." | |
# Read in ./images/letters.svg. | |
svg = open(os.path.join(app.root_path, 'images', 'letters.svg')).read() | |
response = make_response(svg) | |
response.content_type = 'image/svg+xml' | |
return response | |
if __name__ == '__main__': | |
app.run(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment