Updated starter pack
This commit is contained in:
16
app.py
16
app.py
@@ -1,13 +1,23 @@
|
||||
from flask import Flask, render_template, request, jsonify, session
|
||||
import json
|
||||
import random
|
||||
from pymongo import MongoClient # Added MongoDB support
|
||||
|
||||
# MongoDB connection
|
||||
MONGO_URI = "mongodb://ai6s3:Student123!@localhost:27017/student_db"
|
||||
client = MongoClient(MONGO_URI)
|
||||
db = client.student_db # Connect to student_db database
|
||||
questions_collection = db.questions # Use questions collection
|
||||
|
||||
app = Flask(__name__)
|
||||
app.secret_key = 'quizimoto_secret_key'
|
||||
|
||||
# Load questions from file
|
||||
with open('questions.json', 'r') as f:
|
||||
questions_data = json.load(f)
|
||||
# Load questions from MongoDB
|
||||
try:
|
||||
questions_data = list(questions_collection.find({}))
|
||||
except Exception as e:
|
||||
print(f"Error loading questions from MongoDB: {e}")
|
||||
questions_data = [] # Fallback to empty list if database connection fails
|
||||
|
||||
# Prize structure (15 levels)
|
||||
PRIZE_LEVELS = [
|
||||
|
||||
Reference in New Issue
Block a user