Django模板中“|”符号的含义是什么?

时间:2021-05-02 16:57:59

I often see something like that: something.property|escape

我经常看到类似的东西: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

编辑:错误地问了这个问题,它说“Python中的含义是什么”,所以按位或答案都是正确的,但无关紧要,请不要贬低它们

3 个解决方案

#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.

obj.property | escape是在模板中应用转义过滤器的方法,HTML将转义该属性的字符串表示形式。

#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.

'escape'过滤器只是其中之一。

The list of built in filters can be found here: Django Documentation - Built-in filters reference

可在此处找到内置过滤器列表:Django文档 - 内置过滤器参考

In a django template the | character definitely does not mean the 'bitwise OR' operator.

在django模板中|字符绝对不代表'按位OR'运算符。

#3


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

这是一个“或”。如果属性不存在/ null,则表示转义。

#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.

obj.property | escape是在模板中应用转义过滤器的方法,HTML将转义该属性的字符串表示形式。

#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.

'escape'过滤器只是其中之一。

The list of built in filters can be found here: Django Documentation - Built-in filters reference

可在此处找到内置过滤器列表:Django文档 - 内置过滤器参考

In a django template the | character definitely does not mean the 'bitwise OR' operator.

在django模板中|字符绝对不代表'按位OR'运算符。

#3


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

这是一个“或”。如果属性不存在/ null,则表示转义。