将 python 变量传递给 dash html 组件

passing python variables to dash html components

我正在尝试访问破折号 html 组件中的 python 变量的值,它给了我一个错误。 这是我已经尝试过的。

    num = 78
    dbc.CardBody(
        [
            html.H5("TEMP", className="card-title"),
            html.P("This card is number ",{{num}}),
    dbc.Button("Go somewhere", color="primary"),
        ], style = {"color":"black" }
    )

想法是显示存储在 num 中的数字作为 P 元素内容的一部分。 我收到以下错误

TypeError: unhashable type: 'set'

有谁知道我能做些什么来解决这个问题。

添加上面评论的答案,因为它有效。 设置数值变量应作为段落的子项直接访问,具体取决于您希望它如何显示。 而不是

html.P("This card is number ",{{num}}

使用在这种情况下有效的解决方案

html.P(num)

或探索其他选项,例如

html.P("text".format(str(num)))
html.P(children=["...text", num]) 

这里是html.P documentation page