Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
什么是'|';在{services | pprint | safe}中是指在django?_Django_Templates - Fatal编程技术网

什么是'|';在{services | pprint | safe}中是指在django?

什么是'|';在{services | pprint | safe}中是指在django?,django,templates,Django,Templates,我知道在views.py文件中: def index(request): person= {'firstname': 'Craig', 'lastname': 'Daniels'} weather= "sunny" context= { 'person': person, 'weather': weather, } return render(request, 'Articles/greeting.html', c

我知道在views.py文件中:

def index(request):
    person= {'firstname': 'Craig', 'lastname': 'Daniels'}
    weather= "sunny"
    context= {
        'person': person,
        'weather': weather,
        }

    return render(request, 'Articles/greeting.html', context)
然后我们可以在greetings.html中执行以下操作:

<h1>Hi {{ person.firstname }} {{ person.lastname }}</h1>

<h1>Today it is {{ weather }}</h1>
它们被称为

基本上,它接受视图传递给它的变量,并以某种方式对其进行处理。|表示左侧的数据将传递到右侧,这是一个返回值的函数

是Python中pprint的包装器,它是将数据结构很好地打印到控制台的函数

与HTML转义有关。本质上,它告诉Django内容在输出到模板之前不需要进一步处理

{{ services|pprint|safe }}