Skip to content

jinja2 incompatibility with paths created using pathlib #870

@breisfeld

Description

@breisfeld

As part of refactoring, I have been converting my application from using os.path to pathlib.

However, it appears that jinja2 is incompatible with paths created using pathlib.Path.

For example, if tdir is a pathlib Path object, the following generates an error:

jinja_environment = Environment(loader=FileSystemLoader(tdir), trim_blocks=False, lstrip_blocks=True),

where the bottom of the error traceback is

    jinja_environment = Environment(loader=FileSystemLoader(tdir),
  File ".../python/anaconda3/lib/python3.6/site-packages/jinja2/loaders.py", line 163, in __init__
    self.searchpath = list(searchpath)
TypeError: 'PosixPath' object is not iterable

If I convert tdir to a string, things work fine.

jinja: v 2.10
python: v3.6.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions