from flask import Flask, make_response, render_template, request from jinja2 import select_autoescape import repos app = Flask(__name__) app.jinja_options['autoescape'] = select_autoescape(default=True) @app.route('/') def index(): return render_template('index.html.jinja') @app.route('/badge/.svg') def badge(package: str): args = request.args versions = repos.get_versions(package, args) newest_version = max(versions.values()) rendered = render_template('badge.svg.jinja', versions=versions, newest_version=newest_version) response = make_response(rendered) response.headers['Content-Type'] = 'image/svg+xml' return response if __name__ == '__main__': app.run()