Skip to content

Commit c81e0e2

Browse files
modifying setup_templates.py functions
1 parent 00e509c commit c81e0e2

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

Templates/Web/setup_templates.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,42 @@
11
import os
2+
import site
23

34
loc = os.getcwd()
45
new_loc = loc.replace("\\", "/")
6+
venv_templates_path = f"{new_loc}/.venv/Lib/site-packages/Templates"
7+
# Get the global site-packages directory
8+
site_packages_path = site.getsitepackages()[0]
9+
global_templates_path = f"{site_packages_path}/Templates"
510

611

712
def get_configs(filename):
8-
with open(f"{new_loc}/Dev/Templates/Web/configs/HTML/{filename}", "r", encoding="utf-8") as file:
13+
if os.path.exists(venv_templates_path):
14+
template_folder = venv_templates_path
15+
elif os.path.exists(global_templates_path):
16+
template_folder = global_templates_path
17+
else:
18+
return "Error: Templates folder not found"
19+
20+
with open(f"{template_folder}/Web/configs/HTML/{filename}", "r", encoding="utf-8") as file:
921
html_content = file.read()
1022
return html_content
1123

1224

1325
def fetch_configs():
14-
return os.listdir(f"{new_loc}/Dev/Templates/configs/HTML/")
26+
if os.path.exists(venv_templates_path):
27+
template_folder = venv_templates_path
28+
elif os.path.exists(global_templates_path):
29+
template_folder = global_templates_path
30+
else:
31+
return "Error: Templates folder not found"
32+
33+
return os.listdir(f"{template_folder}/configs/HTML/")
1534

1635

1736
def setup_configs():
1837
flask_app = """
1938
from flask import Flask, render_template
20-
import Dev.Templates.setup_templates as ds
39+
import Templates.setup_templates as ds
2140
import os
2241
2342
app = Flask(__name__)

0 commit comments

Comments
 (0)