What does “|” sign mean in a Django template?

浪尽此生 提交于 2020-01-03 11:52:05

问题


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


回答1:


obj.property|escape is the way to apply the escape filter in a template, which will HTML escape the string representation of that property.




回答2:


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.




回答3:


It's a bitwise "or". It means escape if the property doesn't exist/is null.



来源:https://stackoverflow.com/questions/417265/what-does-sign-mean-in-a-django-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!