Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cmt120-2
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Felix Chadwick-Smith
cmt120-2
Commits
1b1a8711
Commit
1b1a8711
authored
1 year ago
by
Felix Chadwick-Smith
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' into 'main'
Renamed See merge request
!13
parents
1d1f8ff6
cf95690b
No related branches found
No related tags found
1 merge request
!13
Renamed
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app.py
+1
-0
1 addition, 0 deletions
app.py
my_flask_app.py
+90
-0
90 additions, 0 deletions
my_flask_app.py
wsgi.py
+3
-9
3 additions, 9 deletions
wsgi.py
with
94 additions
and
9 deletions
app.py
+
1
−
0
View file @
1b1a8711
import
os
import
secrets
import
secrets
from
flask
import
Flask
,
render_template
,
request
,
redirect
,
url_for
,
send_from_directory
,
abort
from
flask
import
Flask
,
render_template
,
request
,
redirect
,
url_for
,
send_from_directory
,
abort
from
flask_sqlalchemy
import
SQLAlchemy
from
flask_sqlalchemy
import
SQLAlchemy
...
...
This diff is collapsed.
Click to expand it.
my_flask_app.py
0 → 100644
+
90
−
0
View file @
1b1a8711
import
os
import
secrets
from
flask
import
Flask
,
render_template
,
request
,
redirect
,
url_for
,
send_from_directory
,
abort
from
flask_sqlalchemy
import
SQLAlchemy
app
=
Flask
(
__name__
,
static_folder
=
'
static
'
)
app
.
config
[
'
SEND_FILE_MAX_AGE_DEFAULT
'
]
=
0
app
.
config
[
'
SQLALCHEMY_DATABASE_URI
'
]
=
'
sqlite:///site.db
'
app
.
config
[
'
SECRET_KEY
'
]
=
secrets
.
token_hex
(
16
)
db
=
SQLAlchemy
(
app
)
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
)
@app.route
(
'
/
'
)
def
home
():
try
:
projects
=
Project
.
query
.
all
()
return
render_template
(
'
index.html
'
,
projects
=
projects
)
except
Exception
as
e
:
print
(
f
"
Error fetching projects:
{
str
(
e
)
}
"
)
return
render_template
(
'
error.html
'
)
# New route for the 'about' page
@app.route
(
'
/about
'
)
def
about
():
return
render_template
(
'
about.html
'
)
# New route for the 'experience' page
@app.route
(
'
/experience
'
)
def
experience
():
# Add logic to fetch data related to the Experience section if needed
return
render_template
(
'
experience.html
'
)
# New route for the 'portfolio' page
@app.route
(
'
/portfolio
'
)
def
portfolio
():
# Add logic to fetch data related to the Portfolio section if needed
return
render_template
(
'
portfolio.html
'
)
# New route for the 'contact' page
@app.route
(
'
/contact
'
)
def
contact
():
return
render_template
(
'
contact.html
'
)
# Updated route for adding a project without Flask-WTF form
@app.route
(
'
/add_project
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
def
add_project
():
if
request
.
method
==
'
POST
'
:
# Retrieve form data directly from request
title
=
request
.
form
.
get
(
'
title
'
)
description
=
request
.
form
.
get
(
'
description
'
)
# Print or log the form data to check if it's received
print
(
f
"
Received form data - Title:
{
title
}
, Description:
{
description
}
"
)
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
'
)
# Updated route for serving the 'my-cv.docx' file
@app.route
(
'
/download_cv
'
)
def
download_cv
():
file_path
=
'
static/my-cv.docx
'
print
(
f
"
Attempting to serve file:
{
file_path
}
"
)
return
send_from_directory
(
'
static
'
,
'
my-cv.docx
'
,
as_attachment
=
True
,
mimetype
=
'
application/docx
'
)
# Updated route for serving assessment files
@app.route
(
'
/download_assessment/<filename>
'
)
def
download_assessment
(
filename
):
try
:
file_path
=
f
'
static/
{
filename
}
'
print
(
f
"
Attempting to serve file:
{
file_path
}
"
)
return
send_from_directory
(
'
static
'
,
filename
,
as_attachment
=
True
)
except
FileNotFoundError
:
print
(
f
"
File not found:
{
file_path
}
"
)
abort
(
404
)
# Return a 404 Not Found error
except
Exception
as
e
:
print
(
f
"
Error serving assessment file:
{
str
(
e
)
}
"
)
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
'
,
8080
)))
This diff is collapsed.
Click to expand it.
wsgi.py
+
3
−
9
View file @
1b1a8711
import
os
from
my_flask_app
import
app
as
application
from
app
import
app
as
application
from
markupsafe
import
Markup
sys
.
modules
[
'
flask
'
].
Markup
=
Markup
if
__name__
==
"
__main__
"
:
application
.
run
()
logging
.
basicConfig
(
stream
=
sys
.
stderr
)
if
__name__
==
'
__main__
'
:
application
.
run
(
host
=
'
0.0.0.0
'
,
port
=
int
(
os
.
environ
.
get
(
'
PORT
'
,
8080
)))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment