如何在Django形式的占位符中写入任意数量的幂或立方

时间:2019-07-19 05:18:44

标签: python django django-forms

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标签尝试过,但是没有用。

1 个答案:

答案 0 :(得分:1)

superscript three HTML entity与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",
)