38 lines
1.4 KiB
Python
38 lines
1.4 KiB
Python
from flask import Flask, render_template, request, abort
|
|
import json
|
|
import html
|
|
|
|
app = Flask(__name__)
|
|
app.config["DEBUG"] = True
|
|
|
|
@app.route("/", methods=["GET", "POST"])
|
|
def index():
|
|
buttons = {0: "418 error",1: "Json Reply",2: "Admin"}
|
|
users = [["benjamyn", 1], ["Test Case", 0]]
|
|
data = {"buttons": buttons, "users": users}
|
|
if request.method == "POST":
|
|
jsonData = json.loads(request.data)
|
|
if "button" in jsonData:
|
|
if jsonData["button"] == '0':
|
|
return abort(418)
|
|
elif jsonData["button"] == '1':
|
|
return json.dumps({"This is a test response": 1, "status": "Success"})
|
|
elif jsonData["button"] == '2':
|
|
return render_template("admin.html", data=data)
|
|
return f"{buttons[int(jsonData['button'])]} was pressed"
|
|
return render_template("testing.html", data=data)
|
|
return render_template("index.html", data=data)
|
|
|
|
@app.route("/otherpage", methods=["POST", "GET"])
|
|
def otherpage():
|
|
buttons = {0: "Other",1: "Pages",2: "Same",3: "Template"}
|
|
data = {"buttons": buttons}
|
|
if request.method == "POST":
|
|
jsonData = json.loads(request.data)
|
|
if jsonData["button"] == '0':
|
|
return render_template("list.html", data=data)
|
|
return jsonData
|
|
return render_template("index.html", data=data)
|
|
|
|
if __name__ == '__main__':
|
|
app.run(host="0.0.0.0") |