Support bundled templates: detect template folder in py2app Resources or working dir
Co-authored-by: Copilot <[email protected]>
This commit is contained in:
1 parent
4cc008b211
commit
672b0148a6
1 file changed
+17
-1
@@ -1,13 +1,29 @@
|
||||
from flask import Flask, render_template, jsonify
|
||||
from datetime import datetime, timezone, timedelta
|
||||
import os
|
||||
import sys
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
from clients import jellyfin
|
||||
|
||||
app = Flask(__name__, template_folder=os.path.join(os.path.dirname(__file__), 'templates'))
|
||||
def _find_template_folder():
|
||||
candidates = [
|
||||
os.path.join(os.path.dirname(__file__), 'templates'),
|
||||
os.path.join(os.path.dirname(sys.executable), '..', 'Resources', 'templates'),
|
||||
os.path.join(os.getcwd(), 'templates'),
|
||||
]
|
||||
for p in candidates:
|
||||
try:
|
||||
p_norm = os.path.normpath(os.path.abspath(p))
|
||||
if os.path.isdir(p_norm):
|
||||
return p_norm
|
||||
except Exception:
|
||||
continue
|
||||
return os.path.join(os.path.dirname(__file__), 'templates')
|
||||
|
||||
app = Flask(__name__, template_folder=_find_template_folder())
|
||||
|
||||
PHT = timezone(timedelta(hours=8))
|
||||
|
||||
|
||||
Reference in new issue
Block a user