如何在 django 中的表单中添加红色星号来显示必填字段?
class ClientForm(forms.ModelForm):
client_number = forms.IntegerField()
name = forms.CharField(max_length=80)
address = forms.CharField(max_length=250)
telephone = forms.CharField(max_length=20)
fax = forms.CharField(max_length=20)
email = forms.EmailField()
alternative_name = forms.CharField(max_length=80, required=False)
alternative_address = forms.CharField(max_length=250, required=False)
alternative_telephone = forms.CharField(max_length=20, required=False)
alternative_email = forms.EmailField(required=False)
其中一些字段是必需的,有些则不是。对于那些需要的字段,有没有一种方法可以添加红色星号来表示该字段是必填字段?
这是我的 html 表单。
{% extends "base.html" %}
{% block content %}
<font>
<h3>Add Client</h3>
</font>
<form method= "POST" action="">
<font>
<div id="form">
<table>
{{form.as_table}}
</table>
<div>
<input type="submit" value="Save" STYLE="background-color:#E8E8E8; color:#181818 "/>
</div>
</div>
</form>
{% endblock %}
class ClientForm(forms.ModelForm):
client_number = forms.IntegerField()
name = forms.CharField(max_length=80)
address = forms.CharField(max_length=250)
telephone = forms.CharField(max_length=20)
fax = forms.CharField(max_length=20)
email = forms.EmailField()
alternative_name = forms.CharField(max_length=80, required=False)
alternative_address = forms.CharField(max_length=250, required=False)
alternative_telephone = forms.CharField(max_length=20, required=False)
alternative_email = forms.EmailField(required=False)
Some of these fields are required and some are not. For those that are required is there a way which I can add a red asterisk to say that this field is required?
Here is my form in html.
{% extends "base.html" %}
{% block content %}
<font>
<h3>Add Client</h3>
</font>
<form method= "POST" action="">
<font>
<div id="form">
<table>
{{form.as_table}}
</table>
<div>
<input type="submit" value="Save" STYLE="background-color:#E8E8E8; color:#181818 "/>
</div>
</div>
</form>
{% endblock %}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如何渲染表单字段及其信息必填
How to render form field with information that it is required