From d13d4860f3d5b51d659379aa8a38742bfe49bf37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tuomas=20Klav=C3=A9r?= Date: Mon, 20 Nov 2023 02:04:12 +0200 Subject: Questions now shows up. DB -> JSON -> JS -> DOM --- get_questions.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 get_questions.py (limited to 'get_questions.py') diff --git a/get_questions.py b/get_questions.py new file mode 100644 index 0000000..496b99a --- /dev/null +++ b/get_questions.py @@ -0,0 +1,18 @@ +from app import app +from flask import render_template, session, request, redirect, jsonify +import db_actions as D + + +@app.route("/get_questions",methods=["GET"]) +def get_questions_by_id(): + if "quiz_id" not in session.keys(): + return "KUOLETTAVA: Sessiota / kyselmä id:tä ei ole" + + results = D.get_questions(session['quiz_id']) + r={} + names=['i','q','n','p','a'] + for i in range(len(results)): + r[i]={} + for j in range(len(results[i])): + r[i][names[j]]=results[i][j] + return (jsonify(r)) -- cgit v1.2.3