Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cmt120-2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Felix Chadwick-Smith
cmt120-2
Commits
9e17dfb3
Commit
9e17dfb3
authored
Jan 8, 2024
by
Felix Chadwick-Smith
Browse files
Options
Downloads
Patches
Plain Diff
sad
parent
3d527bab
Branches
Branches containing commit
No related tags found
1 merge request
!4
sad
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
app.py
+4
-15
4 additions, 15 deletions
app.py
models.py
+11
-0
11 additions, 0 deletions
models.py
with
15 additions
and
15 deletions
app.py
+
4
−
15
View file @
9e17dfb3
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
This diff is collapsed.
Click to expand it.
models.py
0 → 100644
+
11
−
0
View file @
9e17dfb3
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
}
)
"
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