from flask import Flask, request, redirect, url_for, make_response, render_template, Markup, send_from_directory, send_file from flask_redis import FlaskRedis import json, abp, markdown app = Flask(__name__) redis = FlaskRedis(app) @app.route("/") def index(): return render_template("index.html") @app.route("/graph", methods=["GET", "POST"]) def graph(): if request.method == 'POST': # Convert the data to a graph state g = abp.GraphState() g.from_json(json.loads(request.data)) # Convert it back to JSON just for fun data = json.dumps(g.to_json(stringify=True)) # Insert into the database redis.execute_command("SET", "graph", data) # Return success return "Posted {} bytes OK".format(len(data)) else: # Get from the database return redis.get("graph") @app.route("/doc") def doc(): body = Markup(markdown.markdown(render_template("doc.md"), extensions=["markdown.extensions.codehilite"])) return render_template("boilerplate.html", body=body)