added script path detection

prepare for PyInstaller
This commit is contained in:
SG
2025-06-14 17:37:33 +03:00
parent 0b31079654
commit ed9d1dade2
6 changed files with 20 additions and 23 deletions

View File

@@ -1,8 +1,17 @@
import sys
from pathlib import Path
from jinja2 import Environment, FileSystemLoader
from config import Config
# Prepare template rendering engine
env = Environment(loader=FileSystemLoader(Config.TEMPLATES_DIR))
if getattr(sys, 'frozen', False):
# Running fron Pyinstaller-packed binary
base_dir = Path(sys._MEIPASS)
else:
# Running as a plain Python app
base_dir = Path(__file__).resolve().parent
env = Environment(loader=FileSystemLoader(f"{base_dir}/{Config.TEMPLATES_DIR}"))
env.globals['header_image'] = Config.HEADER_IMAGE
index_template = env.get_template("index.html")
content_item_template = env.get_template("content_item.html")
content_item_template = env.get_template("content_item.html")