如何在 django 形式的占位符中编写任何数字的幂或立方体


other_quantity = forms.IntegerField(
    required=False,
    widget=forms.TextInput(
        attrs={"class": "form-control", "placeholder": "in meter cube(m3)"}
    ),
    label="<b>#</b> Quantity of Other  Material to be Remove ",
)

我想在我的占位符中使用立方米符号。尝试使用sup标签,但它不起作用。

将上标三个 HTML 实体与 Django 的mark_safe结合使用。

from django.utils.safestring import mark_safe
mark_safe("in m&sup3;")

在您的情况下,这将是

from django.utils.safestring import mark_safe
...
other_quantity = forms.IntegerField(
    required=False,
    widget=forms.TextInput(
        attrs={"class": "form-control", "placeholder": mark_safe("in m&sup3;")}
    ),
    label="<b>#</b> Quantity of Other  Material to be Remove",
)

最新更新