【发布时间】:2021-01-17 21:49:43
【问题描述】:
我有这个View,我在其中生成一个百分比值,该值取决于后端的某些逻辑。
def my_view(request):
#[..other stuff..]
perc_value = 80 # this changes with the logic above
context = {'perc_value': perc_value}
return render(...)
在我的HTML 中,我需要渲染一个进度条,其中填充有perc_value,如下所示:
<div class="progress progress-xl mb-2">
<div class="progress-bar" role="progressbar" style="width: {{ perc_value }}">{{ perc_value }}%</div>
</div>
我发现了这个类似的问题 (link),它已经很老了,我找不到让它工作的方法。解决此类问题的最佳方法是什么?
【问题讨论】:
-
尝试将
%放在 {{ perc_value }} 之后。还要确保将context传递给render
标签: django