This is the backend source code of this website, written in Flask
from flask import Flask, render_template, send_from_directory
import markdown
import os
import json
app=Flask(__name__, static_folder='static', template_folder='templates')
@app.route('/')
def index():
return render_template('html/index.html', name='index')
@app.route('/projects')
def projects():
project_names=[]
for file in os.listdir("projects"):
if file.endswith(".json"):
project_names.append(file.removesuffix('.json'))
return render_template('html/projects.html', project_names=project_names, name='projects')
@app.route('/projects/<path:path>')
def get_project(path):
with open(f'projects/{path}.json', 'r') as f:
data=json.loads(f.read())
with open(f'projects/{path}.code', 'r') as f:
code=f.read()
return render_template(f'html/project_template.html', name='projects',
project_title=data["project_title"], language=data["language"],
code=code, description=data["description"], link=data["link"])
@app.errorhandler(404)
def not_found(e):
return render_template('html/error_pages/404.html'), 404
@app.errorhandler(500)
def internal_error(e):
with open('error_log.txt', 'a') as f:
f.write('=========ERROR=========')
f.write(str(e))
f.write('=========ERROR=========')
return render_template('html/error_pages/500.html'), 500
if __name__=='__main__':
app.run(debug=True, host='0.0.0.0', port=80)