简体   繁体   English

如何通过函数调用在python django模板中设置变量?

[英]How to set variable in python django template from a function call?

I have the following library which returns a dict:我有以下库返回一个字典:

{% load path_parts %}

I can successfully call the method and print the value:我可以成功调用该方法并打印值:

{% path_parts request.get_full_path %}

I would like to assign the dict to a variable, but I cannot:我想将 dict 分配给一个变量,但我不能:

{% with paths=path_parts request.get_full_path %}

How can I assign a result of a function call to a variable?如何将函数调用的结果分配给变量?

You must try this instead :你必须试试这个:

{% with path_parts request.get_full_path as paths %}
    <!-- use paths here -->
{% endwith %}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM