Main page updated
This commit is contained in:
44
main.py
44
main.py
@ -1,4 +1,8 @@
|
||||
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
|
||||
@ -8,10 +12,23 @@ from templates.uni.subjects.szamitogepek_mukodese.szgm_app import szamitogepek_m
|
||||
app = Flask(__name__)
|
||||
app.secret_key = 'your_secret_key'
|
||||
|
||||
|
||||
|
||||
@app.route('/')
|
||||
@app.route('/home')
|
||||
def home():
|
||||
return render_template('home.html')
|
||||
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():
|
||||
@ -26,12 +43,35 @@ def uni():
|
||||
|
||||
@app.route('/projects')
|
||||
def projects():
|
||||
return render_template('projects.html')
|
||||
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')
|
||||
|
Reference in New Issue
Block a user