开发者

How do I put a a red asterisk to show a required field in a form in django?

开发者 https://www.devze.com 2023-02-02 15:53 出处:网络
class ClientForm(forms.ModelForm): client_number = forms.IntegerField() name = forms.CharField(max_length=80)
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 %}


How to render form field with information that it is required

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号