added script path detection
prepare for PyInstaller
This commit is contained in:
13
jinja_env.py
13
jinja_env.py
@@ -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")
|
||||
Reference in New Issue
Block a user