Skip to content
Snippets Groups Projects
Commit 9e17dfb3 authored by Felix Chadwick-Smith's avatar Felix Chadwick-Smith
Browse files

sad

parent 3d527bab
Branches
No related tags found
1 merge request!4sad
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')
\ No newline at end of file
# 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
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
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)
def __repr__(self):
return f"Project(id={self.id}, title={self.title}, description={self.description})"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment