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

Merge branch 'master' into 'main'

added refferences

See merge request !29
parents 7121d0c1 09445d2d
No related branches found
No related tags found
1 merge request!29added refferences
No preview for this file type
File deleted
No preview for this file type
#https://users.cs.cf.ac.uk/MoloughneyMJ/FlaskReference/FlaskCribSheets very helpful for setting it up for the first time
#https://realpython.com/flask-project/#create-a-virtual-environment - showed me how to expand on inital setup
import os import os
import secrets import secrets
from flask import Flask, render_template, request, redirect, flash from flask import Flask, render_template, request, redirect, flash
#https://flask.palletsprojects.com/en/3.0.x/quickstart/#a-minimal-application for inital flask set up
from flask import Flask, render_template, request, redirect, url_for, send_from_directory, abort, current_app from flask import Flask, render_template, request, redirect, url_for, send_from_directory, abort, current_app
from flask_sqlalchemy import SQLAlchemy from flask_sqlalchemy import SQLAlchemy
from flask_wtf import FlaskForm from flask_wtf import FlaskForm
...@@ -10,6 +13,8 @@ from wtforms.validators import DataRequired ...@@ -10,6 +13,8 @@ from wtforms.validators import DataRequired
app = Flask(__name__, static_folder='static') app = Flask(__name__, static_folder='static')
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0 app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
#https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-iv-database
#https://realpython.com/flask-by-example-part-2-postgres-sqlalchemy-and-alembic/
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.abspath(os.path.join(os.path.dirname(__file__), 'instance/site.db')) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.abspath(os.path.join(os.path.dirname(__file__), 'instance/site.db'))
app.config['SECRET_KEY'] = secrets.token_hex(16) app.config['SECRET_KEY'] = secrets.token_hex(16)
...@@ -24,6 +29,7 @@ class ProjectForm(FlaskForm): ...@@ -24,6 +29,7 @@ class ProjectForm(FlaskForm):
title = StringField('Title', validators=[DataRequired()]) title = StringField('Title', validators=[DataRequired()])
description = TextAreaField('Description', validators=[DataRequired()]) description = TextAreaField('Description', validators=[DataRequired()])
submit = SubmitField('Add Project') submit = SubmitField('Add Project')
#https://flask.palletsprojects.com/en/3.0.x/quickstart/#a-minimal-application - Routes for developing my routes for each page
@app.route('/') @app.route('/')
def home(): def home():
...@@ -75,6 +81,7 @@ def add_project(): ...@@ -75,6 +81,7 @@ def add_project():
return render_template('add_project.html', form=form) return render_template('add_project.html', form=form)
# Updated route for serving the 'my-cv.docx' file # Updated route for serving the 'my-cv.docx' file
@app.route('/download_cv') @app.route('/download_cv')
#https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xx-some-javascript-magic
def download_cv(): def download_cv():
file_path = 'static/my-cv.docx' file_path = 'static/my-cv.docx'
print(f"Attempting to serve file: {file_path}") print(f"Attempting to serve file: {file_path}")
...@@ -99,4 +106,5 @@ def download_assessment(filename): ...@@ -99,4 +106,5 @@ def download_assessment(filename):
if __name__ == '__main__': if __name__ == '__main__':
with app.app_context(): with app.app_context():
db.create_all() db.create_all()
#https://flask.palletsprojects.com/en/3.0.x/quickstart/#a-minimal-application for learning how to debug
app.run(debug=False, port=int(os.environ.get('PORT', 8080))) app.run(debug=False, port=int(os.environ.get('PORT', 8080)))
\ No newline at end of file
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
</head> </head>
<body class="home-page"> <body class="home-page">
<!---https://realpython.com/flask-project/#create-a-virtual-environment--->
<nav> <nav>
<ul> <ul>
<li><a href="{{ url_for('home') }}">Home</a></li> <li><a href="{{ url_for('home') }}">Home</a></li>
...@@ -27,6 +28,7 @@ ...@@ -27,6 +28,7 @@
</ul> </ul>
</nav> </nav>
<h2>Add Project</h2> <h2>Add Project</h2>
<!---https://realpython.com/flask-project/#create-a-virtual-environment--->
<form method="POST" action="{{ url_for('add_project') }}"> <form method="POST" action="{{ url_for('add_project') }}">
{% with messages = get_flashed_messages() %} {% with messages = get_flashed_messages() %}
{% if messages %} {% if messages %}
...@@ -36,7 +38,7 @@ ...@@ -36,7 +38,7 @@
{% endfor %} {% endfor %}
</ul> </ul>
{% endif %} {% endif %}
{% endwith %} {% endwith %}
{% if form %} {% if form %}
{{ form.csrf_token }} {{ form.csrf_token }}
<div class="form-group"> <div class="form-group">
......
<!---https://css-tricks.com/crafting-reusable-html-templates/-->
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
......
work-1.png

889 KiB

work-3.png

706 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment