Reputation: 41
I get this type of error while creating template file. I have simple use this type of syntax:
{{ "hello\how\are" | basename}}
Please help me solve it.
Thanks
Upvotes: 3
Views: 18242
Reputation: 2261
I had a similar error in a stand-alone program that uses Jinja2. In my case I didn't have an app, so I couldn't use app.add_template_filter. I had an Environment instance which has a filters dict. I added to that dict and the filtering went fine. If 'e' is the environment, I did something like this:
e.filters['basename'] = basename
Assuming a basename function in the previous answer. With an app, app.jinja_env exposes the environment, so that becomes:
app.jinja_env.filters['basename'] = basename
Upvotes: 3
Reputation: 3010
From what I see in Jinja2 official documentation there is no basename
filter.
See Jinja2 - List of Builtin Filters.
EDIT:
You can write yor own basename
filter, for example:
def basename(text):
return text.split('\\')[-1]
app.add_template_filter(basename)
Upvotes: 4