-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
45 lines (33 loc) · 1.11 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from flask import Flask, jsonify, request, render_template
import mysql.connector
from mysql.connector import errorcode
app = Flask(__name__)
try:
con = mysql.connector.connect(user="divyansh", password="23ab89DS!", host="divyansh-quiz.mysql.database.azure.com", database="quiz")
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with the user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exist")
else:
print(err)
@app.route('/')
def error():
return render_template('error.html')
else:
cur = con.cursor()
cur.execute("select count(*) from questions")
no_of_rows = cur.fetchone()
@app.route('/')
def index():
return render_template('index.html')
@app.route("/quizAPI", methods=["GET"])
def get_quesion():
cur.execute("select * from questions")
ques_data = cur.fetchall()
question = []
for data in ques_data:
question.extend([data])
return jsonify(question)
if __name__== '__main__':
app.run(host = "0.0.0.0", port=5000)