mirror of
https://github.com/asimonson1125/asimonson1125.github.io.git
synced 2026-02-25 05:09:49 -06:00
Obsessive error handling
This commit is contained in:
26
.vscode/launch.json
vendored
Normal file
26
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Python Debugger: Flask",
|
||||
"type": "debugpy",
|
||||
"request": "launch",
|
||||
"cwd": "${workspaceFolder}/src",
|
||||
"module": "flask",
|
||||
"env": {
|
||||
"FLASK_APP": "app.py",
|
||||
"FLASK_DEBUG": "1",
|
||||
|
||||
},
|
||||
"args": [
|
||||
"run",
|
||||
"--no-debugger",
|
||||
"--no-reload"
|
||||
],
|
||||
"jinja": true
|
||||
}
|
||||
]
|
||||
}
|
||||
30
src/app.py
30
src/app.py
@@ -2,11 +2,14 @@ import flask
|
||||
from flask_minify import Minify
|
||||
import json
|
||||
from tasks import TaskHandler
|
||||
import werkzeug.exceptions as HTTPerror
|
||||
|
||||
proj = json.load(open("./static/json/projects.json", "r"))
|
||||
books = json.load(open("./static/json/books.json", "r"))
|
||||
skillList = json.load(open("./static/json/skills.json", "r"))
|
||||
timeline = json.load(open("./static/json/timeline.json", "r"))
|
||||
pages = json.load(open("./static/json/pages.json", "r"))
|
||||
pages['about']['skillList'] = skillList
|
||||
pages['about']['timeline'] = timeline
|
||||
pages['projects']['projects'] = proj
|
||||
pages['home']['books'] = books
|
||||
@@ -20,14 +23,35 @@ tasks = TaskHandler()
|
||||
@app.route('/api/goto/<location>')
|
||||
def goto(location='home'):
|
||||
pagevars = pages[location]
|
||||
return [pagevars, flask.render_template(pagevars["template"], var=pagevars)]
|
||||
page = None
|
||||
try:
|
||||
page = flask.render_template(pagevars["template"], var=pagevars)
|
||||
except Exception as e:
|
||||
e = HTTPerror.InternalServerError(None, e)
|
||||
page = page404(e)
|
||||
return [pagevars, page]
|
||||
|
||||
# I am literally insane
|
||||
# There was no reason for me to do this
|
||||
# it saved some lines of code I guess
|
||||
# infinite flaskless flask here we comes
|
||||
|
||||
def funcGen(pagename, pages):
|
||||
def dynamicRule():
|
||||
try:
|
||||
return flask.render_template('header.html', var=pages[pagename])
|
||||
except Exception:
|
||||
e = HTTPerror.InternalServerError()
|
||||
return page404(e)
|
||||
return dynamicRule
|
||||
|
||||
for i in pages:
|
||||
exec(f"@app.route(pages['{i}']['canonical'])\ndef {i}(): return flask.render_template('header.html', var=pages['{i}'])")
|
||||
func = funcGen(i, pages)
|
||||
app.add_url_rule(pages[i]['canonical'], i, func)
|
||||
|
||||
|
||||
# for i in pages:
|
||||
# exec(f"@app.route(pages['{i}']['canonical'])\ndef {i}(): return flask.render_template('header.html', var=pages['{i}'])")
|
||||
|
||||
|
||||
@app.route("/resume")
|
||||
@@ -85,4 +109,4 @@ if __name__ == "__main__":
|
||||
# sass.compile(dirname=("static/scss", "static/css"), output_style="compressed")
|
||||
app.run()
|
||||
else:
|
||||
Minify(app=app, html=True, js=True, cssless=True)
|
||||
Minify(app=app, html=True, js=True, cssless=True)
|
||||
|
||||
Reference in New Issue
Block a user