Skip to content
Snippets Groups Projects

sad

2 files
+ 15
15
Compare changes
  • Side-by-side
  • Inline

Files

+ 4
15
import os
import secrets
from flask import Flask, render_template, request, redirect, url_for, send_from_directory
from flask import Flask, render_template, request, redirect, url_for, send_from_directory, abort
from flask_sqlalchemy import SQLAlchemy
from flask import abort, jsonify
app = Flask('cmt120_2', static_folder='static')
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
# Generate a secure random key
secret_key = secrets.token_hex(16)
app.config['SECRET_KEY'] = secret_key
app.config['SECRET_KEY'] = secrets.token_hex(16)
db = SQLAlchemy(app)
# Define the Project model
class Project(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(100), nullable=False)
description = db.Column(db.Text, nullable=False)
# Existing route for the home page
@app.route('/')
def home():
try:
projects = Project.query.all()
return render_template('index.html', projects=projects)
except Exception as e:
# Handle the error, log it, or render an error template
print(f"Error fetching projects: {str(e)}")
return render_template('error.html')
@app.route('/about')
def about():
return render_template('about.html')
@@ -85,12 +79,7 @@ def download_assessment(filename):
abort(500)
if __name__ == '__main__':
# Create database tables
with app.app_context():
db.create_all()
# Use '0.0.0.0' to allow external access
app.run(debug=True, host='0.0.0.0')
# Uncomment the following line if you're deploying on OpenShift and use port 8080
# app.run(debug=True, host='0.0.0.0', port=8080)
\ No newline at end of file
app.run(debug=True, host='0.0.0.0')
\ No newline at end of file
Loading