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

added new app.py

parent fe602645
No related branches found
No related tags found
1 merge request!6Master
......@@ -2,7 +2,6 @@ import os
import secrets
from flask import Flask, render_template, request, redirect, url_for, send_from_directory, abort
from flask_sqlalchemy import SQLAlchemy
from wtforms import StringField, SubmitField
app = Flask(__name__, static_folder='static')
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
......@@ -16,10 +15,6 @@ class Project(db.Model):
title = db.Column(db.String(100), nullable=False)
description = db.Column(db.Text, nullable=False)
class AddProjectForm():
# Remove FlaskForm-related code
pass
@app.route('/')
def home():
try:
......@@ -51,21 +46,23 @@ def portfolio():
def contact():
return render_template('contact.html')
# Updated route for adding a project with Flask-WTF form
# Updated route for adding a project without Flask-WTF form
@app.route('/add_project', methods=['GET', 'POST'])
def add_project():
form = AddProjectForm()
if request.method == 'POST':
# Retrieve form data directly from request
title = request.form.get('title')
description = request.form.get('description')
if form.validate_on_submit():
# Print or log the form data to check if it's received
print(f"Received form data - Title: {form.title.data}, Description: {form.description.data}")
print(f"Received form data - Title: {title}, Description: {description}")
new_project = Project(title=form.title.data, description=form.description.data)
new_project = Project(title=title, description=description)
db.session.add(new_project)
db.session.commit()
return redirect(url_for('home'))
return render_template('add_project.html', form=form)
return render_template('add_project.html')
# Updated route for serving the 'my-cv.docx' file
@app.route('/download_cv')
......@@ -89,5 +86,3 @@ def download_assessment(filename):
app.logger.exception(f"Error serving assessment file: {str(e)}")
abort(500)
if __name__ == '__main__':
app.run(debug=True, port=int(os.environ.get('PORT', 5000)))
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment