pallets / jinja

A very fast and expressive template engine.
https://jinja.palletsprojects.com
BSD 3-Clause "New" or "Revised" License
10.23k stars 1.6k forks source link

.get_template() not work with path Windows slashes (\). #1891

Closed Gdahuks closed 11 months ago

Gdahuks commented 11 months ago

Jinja does not always recognize Windows slashes (). This kind of slash is returned when you use Windows os.path.join()

from jinja2 import Environment, FileSystemLoader
env = Environment(
    loader= FileSystemLoader("here\\windows\\slashes\\work")
)
template = env.get_template("here\\windows\\slashes\\NOT\\work.jinja")

.get_template() should work even if the path is defined in Windows format (if the Windows system is used). I will prepare PR fixing this issue by myself.

Environment:

ThiefMaster commented 11 months ago

Template names always use forward slashes, there are previous issues about this topic: https://github.com/pallets/jinja/issues/767, https://github.com/pallets/jinja/issues/880

PS: Even for filesystem paths you do not have to use backslashes - internally even all the Windows APIs work fine with forward slashes.