pallets / jinja

A very fast and expressive template engine.

Home Page:https://jinja.palletsprojects.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

Gdahuks opened this issue · comments

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:

  • Python version: 3.9.13
  • Jinja version: 3.1.2

Template names always use forward slashes, there are previous issues about this topic: #767, #880

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