-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
28 lines (23 loc) · 743 Bytes
/
app.py
File metadata and controls
28 lines (23 loc) · 743 Bytes
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
from flask import Flask, jsonify
import pymysql
from pymysql.cursors import DictCursor
app = Flask(__name__)
# MySQL configuration for XAMPP
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_USER'] = 'root'
app.config['MYSQL_PASSWORD'] = ''
app.config['MYSQL_DB'] = 'students_db'
def get_db_connection():
return pymysql.connect(
host=app.config['MYSQL_HOST'],
user=app.config['MYSQL_USER'],
password=app.config['MYSQL_PASSWORD'],
database=app.config['MYSQL_DB'],
cursorclass=DictCursor,
autocommit=True
)
@app.route('/')
def home():
return "Students and Subjects API - Access /students or /subjects endpoints"
if __name__ == '__main__':
app.run(debug=True, port=5000)