from flask import Flask, render_template, request import solver app = Flask(__name__) @app.route("/", methods=["GET", "POST"]) def index(): if request.method == "GET": return render_template("page.html") else: try: M = int(request.form["M"]) N = int(request.form["N"]) except ValueError: return render_template("page.html", invalid=True) if not (1 <= M <= 40 and 1 <= N <= 40): return render_template("page.html", invalid=True) g = solver.construct(M, N) if g is None: return render_template("page.html", nosol=True, M=M, N=N) else: image, works = g.plot() return render_template("page.html", image=image, works=works, M=M, N=N) if __name__ == "__main__": app.run( host="0.0.0.0", port=8000 )