如何在django中放置一个红色星号来显示表单中的必填字段?

时间:2011-01-04 14:03:27

标签: django forms views models

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 %}