Update app.py
Browse files
app.py
CHANGED
|
@@ -11,6 +11,26 @@ app.secret_key = 'your_super_secret_key'
|
|
| 11 |
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db'
|
| 12 |
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
# Initialize SQLAlchemy
|
| 15 |
db = SQLAlchemy(app)
|
| 16 |
|
|
|
|
| 11 |
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db'
|
| 12 |
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
| 13 |
|
| 14 |
+
import sqlite3
|
| 15 |
+
from datetime import timedelta
|
| 16 |
+
|
| 17 |
+
# Flask App Setup
|
| 18 |
+
app = Flask(__name__)
|
| 19 |
+
|
| 20 |
+
# Secret key is used to sign session data (must be kept secret in real apps!)
|
| 21 |
+
app.secret_key = "supersecretkey"
|
| 22 |
+
|
| 23 |
+
# Permanent sessions last for 7 days (used when "Remember Me" is checked)
|
| 24 |
+
app.permanent_session_lifetime = timedelta(days=7)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
# Helper function to connect to SQLite database
|
| 28 |
+
def get_db_connection():
|
| 29 |
+
# Connect to SQLite database (creates file users.db if it doesn’t exist)
|
| 30 |
+
conn = sqlite3.connect("users.db")
|
| 31 |
+
conn.row_factory = sqlite3.Row # Makes rows behave like dictionaries
|
| 32 |
+
return conn
|
| 33 |
+
|
| 34 |
# Initialize SQLAlchemy
|
| 35 |
db = SQLAlchemy(app)
|
| 36 |
|