From 46fc7a7a636c7f53fe6fc486bbfe73f56d2cbdda Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Sat, 19 Dec 2020 19:24:35 +0530 Subject: [PATCH] Add admin page --- app.py | 10 +++++-- templates/admin.html | 67 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 templates/admin.html diff --git a/app.py b/app.py index 8f9ec94..012fb31 100644 --- a/app.py +++ b/app.py @@ -1,17 +1,17 @@ import json -from flask import Flask, jsonify, request +from flask import Flask, jsonify, request, render_template app = Flask(__name__) with open("data.json") as f: data = json.load(f) -@app.route('/all/') +@app.route("/all/") def get_all(): return jsonify(data) -@app.route('/data/', methods=["POST"]) +@app.route("/data/", methods=["POST"]) def set_data_point(data_id): try: value = request.json["value"] @@ -22,3 +22,7 @@ def set_data_point(data_id): with open("data.json", "w") as f: json.dump(data, f) return jsonify({"success": True}) + +@app.route("/admin/") +def admin(): + return render_template("admin.html", data=data) diff --git a/templates/admin.html b/templates/admin.html new file mode 100644 index 0000000..dd263bc --- /dev/null +++ b/templates/admin.html @@ -0,0 +1,67 @@ + + + + + + Mock Car API Admin + + + +

Mock Data API

+
+ + + +
+ + + + + + {% for key, value in data.items() %} + + + + + {% endfor %} +
KeyValue
{{ key }}{{ value }}
+ + +