这是模板部分的当前版本,但它不起作用,因为大括号正在解释为字符串的一部分。如何传递object.id值而不是字符串本身?
df3$NAs <- ave(df$value,df$name,FUN=function(x) sum(is.na(x))))
df3$name1 <- paste0(df3$name,' (NA = ',df3$NAs,')')
ggplot(data=df3, aes(time, value)) +
geom_line() +
geom_point() + facet_wrap(~ name1, nrow=1)
答案 0 :(得分:0)
add
模板标记专为数字操作而设计:
@register.filter(is_safe=False)
def add(value, arg):
"""Adds the arg to the value."""
try:
return int(value) + int(arg)
except (ValueError, TypeError):
try:
return value + arg
except Exception:
return ''
我刚刚编写了自己的模板标签:
@register.filter
def addstr(arg1, arg2):
"""concatenate arg1 & arg2"""
return unicode(arg1) + unicode(arg2)
并使用它:
{% with "SendTransfer,Отправить перевод,"|addstr:object.id as submit_args %}
{% with form|with_submit:submit_args as submit_form %}
{% crispy submit_form %}
{% endwith %}
{% endwith %}