Files
Personal-Website-Project/main.py
2025-01-12 20:17:25 +01:00

84 lines
2.7 KiB
Python

from flask import Flask, render_template, request, redirect, url_for, session
import random
import json
import os
import datetime
from templates.uni.subjects.halozatok.halozatok_app import halozatok_vizsga_teszt
from templates.uni.subjects.portalfejlesztes_net_ben.portalfejlesztes_app import portalfejlesztes_net_ben
from templates.uni.subjects.vallalati_informacios_rendszerek.vir_app import vallalati_informacios_rendszerek
from templates.uni.subjects.szamitogepek_mukodese.szgm_app import szamitogepek_mukodese
app = Flask(__name__)
app.secret_key = 'your_secret_key'
@app.route('/')
@app.route('/home')
def home():
quotes = []
with open('./static/text_files/home/quotes.json', 'r', encoding='utf-8') as f:
quotes = json.load(f)
quote = random.sample(quotes, 1)
posts = []
with open("posts.json", "r") as f:
posts = json.load(f)
posts.reverse()
print(posts)
return render_template('home/home.html', quote=quote[0], post_data=posts[:6])
@app.route('/about')
def about():
return render_template('about/about.html')
@app.route('/uni')
def uni():
session.pop('question_index', None)
session.pop('answers', None)
session.pop('quiz_questions', None)
return render_template('uni/uni.html')
@app.route('/projects')
def projects():
return render_template('projects/projects.html')
@app.route('/git')
def git():
return render_template('git.html')
@app.route('/posts/<slug>')
def post(slug):
posts = []
with open("posts.json", "r") as f:
posts = json.load(f)
# Find the post with the matching slug
post = next((p for p in posts if p['slug'] == slug), None)
if not post:
abort(404)
# Now we need to render a template that corresponds to the slug.
# Let's assume that the HTML file is named like the slug (e.g., 'my-first-post.html').
template_name = f"posts/{slug}.html" # looks for a file like posts/my-first-post.html
# Check if the template file exists before rendering
if not os.path.exists(os.path.join('templates', template_name)):
abort(404) # If the file does not exist, show 404 error
# Render the post template
return render_template(template_name, post=post)
# Register the blueprints with appropriate URL prefixes
app.register_blueprint(halozatok_vizsga_teszt, url_prefix='/uni/halozatok')
app.register_blueprint(portalfejlesztes_net_ben, url_prefix='/uni/portalfejlesztes_net_ben')
app.register_blueprint(vallalati_informacios_rendszerek, url_prefix='/uni/vallalati_informacios_rendszerek')
app.register_blueprint(szamitogepek_mukodese, url_prefix='/uni/szamitogepek_mukodese')
if __name__ == '__main__':
app.run(debug=True, host='127.0.0.1', port=5000)