I have this code:
app=Quart(__name__)
print(app.jinja_loader.searchpath)
app.jinja_loader.searchpath.append(os.path.join(os.getcwd(),app.config["BASE_TEMPLATE_FOLDER"]))
print(app.jinja_loader.searchpath)
app.config["BASE_TEMPLATE_FOLDER"]
returns the string path to the directory of my base.html
. The pathing is correct but for some reason app.jinja_loader.searchpath
is not updating. Its a list so it should be mutable but it doesn't change whether I use .append()
, +=[]
or whether I completely assign it to a new list.
However, when I run
print(app.jinja_loader.searchpath+[os.path.join(os.getcwd(),app.config["BASE_TEMPLATE_FOLDER"])])
It outputs what I want it to output which is a list containing the path I want to append.
I must update the jinja_loader.searchpath
because by default it only points to the main template folder when I also need it to point to another template folder containing the base.html
.
I was using flask
before but I only just changed my project to run using quart
. Changing the searchpath on flask worked as expected but only after changing to quart is when this problem began occurring.
ChatGPT suggested I reassign the FileSystemLoader
:
from jinja2 import FileSystemLoader
app.jinja_loader=FileSystemLoader(app.jinja_loader.searchpath+[os.path.join(os.getcwd(),app.config["BASE_TEMPLATE_FOLDER"])])
But then I get the error: AttributeError: can't set attribute 'jinja_loader'
This is a baffling situation considering no errors are being raised, its just the searchpath won't change, which then induces an error of my base.html
not being found but thats irrelevant since my pathing is correct as I mentioned before.
Any help would be much appreciated.