Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,18 @@ from flask_cors import CORS
|
|
| 6 |
|
| 7 |
app = Flask(__name__)
|
| 8 |
CORS(app) # Enable CORS for all routes (for front-end testing on a different port/domain)
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
def load_events():
|
| 12 |
if not os.path.exists(DATA_FILE):
|
|
@@ -43,7 +54,7 @@ def index():
|
|
| 43 |
|
| 44 |
return render_template('index.html', events=events, reminders=reminders, search=search_query)
|
| 45 |
|
| 46 |
-
# Get all events
|
| 47 |
@app.route('/events', methods=['GET', 'POST'])
|
| 48 |
@app.route('/events/', methods=['GET', 'POST']) # For routes with trailing slash
|
| 49 |
def events():
|
|
|
|
| 6 |
|
| 7 |
app = Flask(__name__)
|
| 8 |
CORS(app) # Enable CORS for all routes (for front-end testing on a different port/domain)
|
| 9 |
+
|
| 10 |
+
DATA_DIR = '/data'
|
| 11 |
+
DATA_FILE = os.path.join(DATA_DIR, 'events.json')
|
| 12 |
+
|
| 13 |
+
# Ensure the /data directory exists
|
| 14 |
+
if not os.path.exists(DATA_DIR):
|
| 15 |
+
os.makedirs(DATA_DIR)
|
| 16 |
+
|
| 17 |
+
# Initialize the events.json file if it doesn't exist
|
| 18 |
+
if not os.path.exists(DATA_FILE):
|
| 19 |
+
with open(DATA_FILE, 'w') as f:
|
| 20 |
+
json.dump([], f)
|
| 21 |
|
| 22 |
def load_events():
|
| 23 |
if not os.path.exists(DATA_FILE):
|
|
|
|
| 54 |
|
| 55 |
return render_template('index.html', events=events, reminders=reminders, search=search_query)
|
| 56 |
|
| 57 |
+
# Get all events or add new event
|
| 58 |
@app.route('/events', methods=['GET', 'POST'])
|
| 59 |
@app.route('/events/', methods=['GET', 'POST']) # For routes with trailing slash
|
| 60 |
def events():
|