What does “|” sign mean in a Django template?
-
03-07-2019 - |
Question
I often see something like that:
something.property|escape
something
is an object, property
is it's string property. escape
- i don't know :)
What does this mean? And what min python version it is used in?
EDIT: The question was asked wrongly, it said "What does | mean in Python", so the bitwise or answers are correct, but irrelevant, please do not downvote them
Solution
obj.property|escape is the way to apply the escape filter in a template, which will HTML escape the string representation of that property.
OTHER TIPS
The pipe character indicates that you want to send the results of the left hand side to the filter defined on the right side. The filter will modify the value in some way.
The 'escape' filter is just one of many.
The list of built in filters can be found here: Django Documentation - Built-in filters reference
In a django template the | character definitely does not mean the 'bitwise OR' operator.
It's a bitwise "or". It means escape if the property doesn't exist/is null.