Paul
Paul

Reputation: 95

How to remove error message in django forms?

I have been looking for several hours how to remove the error messages which appear over my Comment form.
When for example someone clicks "Send your button" with an empty text, the following error message "This field is required" appears.
I want this field required BUT NOT appearing error messages.

Here is the code:

HTML

<form action="/s={{ s }}/a={{ a }}/comment/q={{ q }}/" method="post">{% csrf_token %}{{ form.as_p }}
<button type="submit">Send your comment</button>
</form>

DJANGO

my_default_errors_comment = {
}

class CommentForm(forms.Form):
    required_css_class = 'required'
    message = forms.CharField(widget=forms.Textarea, label=u'', max_length=200, required=True, error_messages=my_default_errors_comment)

Even when I remove the "my_default_errors_comment" things, the error message still appear.

Can someone please help? Note: My required css class is just adding an asterisk after the field.

Thank you a lot in advance!

Upvotes: 0

Views: 4538

Answers (1)

The Django Ninja
The Django Ninja

Reputation: 393

You can achieve it like this :

From the Django docs

<form action="/s={{ s }}/a={{ a }}/comment/q={{ q }}/" method="post">{% csrf_token %}

    {% for field in form %}
        <div class="fieldWrapper">
            {# uncomment to display field errors #}
            {# {{ field.errors }} #} 

            {{ field.label_tag }} {{ field }}
        </div>
    {% endfor %}
    <button type="submit">Send your comment</button>
</form>

Upvotes: 1

Related Questions