aboutsummaryrefslogtreecommitdiff
path: root/src/match_up/__init__.py
diff options
context:
space:
mode:
authorKaran Jayachandra <mail@karanjayachandra.com>2024-11-08 17:30:19 +0100
committerKaran Jayachandra <mail@karanjayachandra.com>2024-11-08 17:30:19 +0100
commit5b01707a04c362ced66428bef8e0234176d212d9 (patch)
tree99e43efa171403cc08c7be28f9ec791462f822a9 /src/match_up/__init__.py
parent2a390e99e03fe538169aa6d7c23669eaa5ece467 (diff)
Added the changes to the templates to pass the url_for function
Diffstat (limited to 'src/match_up/__init__.py')
-rw-r--r--src/match_up/__init__.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/match_up/__init__.py b/src/match_up/__init__.py
index badf3f0..3a78b8d 100644
--- a/src/match_up/__init__.py
+++ b/src/match_up/__init__.py
@@ -1,19 +1,24 @@
from dotenv import load_dotenv
+from importlib.resources import path
from match_up.controller import RoundGenerator
from match_up.model import CourtList, PlayerList
-from jinja2 import FileSystemLoader, Environment
-from flask import Flask, render_template, request
-
+from jinja2 import FileSystemLoader, Environment, PackageLoader
+from flask import Flask, render_template, request, url_for
load_dotenv()
-app = Flask("Match Up! Backend")
+with path("match_up", "static") as p:
+ static_folder = p
+with path("match_up", "templates") as p:
+ template_folder = p
+app = Flask("Match Up! Backend", static_folder=static_folder, template_folder=template_folder)
rg = RoundGenerator(courts=CourtList(), players=PlayerList())
-re = Environment(loader=FileSystemLoader("templates"))
+re = Environment(loader=PackageLoader("match_up"))
@app.route("/", methods=["GET"])
def home():
- return render_template("index.j2")
+ template = re.get_template("index.j2").render(url_for=url_for)
+ return template
@app.route("/time", methods=["GET"])
@@ -74,7 +79,8 @@ def toggle_player(player_request):
@app.route("/players", methods=["GET"])
def get_list_of_players():
- return render_template("players.j2", players=rg.players.get_players())
+ template = re.get_template("players.j2").render(players=rg.players.get_players(), url_for=url_for)
+ return template
@app.route("/court-toggle/<court_number>", methods=["POST"])