Skip to content

Commit

Permalink
GH-1: Extract Jinja loader function
Browse files Browse the repository at this point in the history
  • Loading branch information
markhobson committed Sep 18, 2023
1 parent e8d6c8a commit ffb8fe8
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions schemes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import os
from flask import Flask, render_template
from jinja2 import ChoiceLoader, FileSystemLoader, PackageLoader, PrefixLoader
from jinja2 import BaseLoader, ChoiceLoader, FileSystemLoader, PackageLoader, PrefixLoader


def create_app() -> Flask:
app = Flask(__name__, static_url_path="/")

app.jinja_loader = ChoiceLoader( # type: ignore
[
FileSystemLoader(os.path.join(app.root_path, str(app.template_folder))),
PrefixLoader({"govuk_frontend_jinja": PackageLoader("govuk_frontend_jinja")})
]
)
app.jinja_loader = create_jinja_loader(app) # type: ignore

@app.route("/")
def index() -> str:
return render_template("index.html")

return app


def create_jinja_loader(app: Flask) -> BaseLoader:
return ChoiceLoader(
[
FileSystemLoader(os.path.join(app.root_path, str(app.template_folder))),
PrefixLoader({"govuk_frontend_jinja": PackageLoader("govuk_frontend_jinja")})
]
)

0 comments on commit ffb8fe8

Please sign in to comment.