You should ALWAYS validate your form on the server side, client side validation is but a convenience for the user only.

That being said, Django forms has a variable form.errors which shows if certain form fields were incorrect.

{{ form.name_of_field.errors }} can give you each individual error of each field that's incorrectly filled out. See more here:

http://docs.djangoproject.com/en/dev/topics/forms/

Answer from AlbertoPL on Stack Overflow
๐ŸŒ
Django Documentation
docs.djangoproject.com โ€บ en โ€บ 5.2 โ€บ ref โ€บ forms โ€บ validation
Form and field validation | Django documentation | Django
Common cases such as validating against an email or a regular expression can be handled using existing validator classes available in Django. For example, validators.validate_slug is an instance of a RegexValidator constructed with the first argument being the pattern: ^[-a-zA-Z0-9_]+\Z. See the section on writing validators to see a list of what is already available and for an example of how to write a validator. Letโ€™s first create a custom form field that validates its input is a string containing comma-separated email addresses.
๐ŸŒ
DEV Community
dev.to โ€บ guzmanojero โ€บ django-under-the-hood-how-form-validation-works--124j
Django under the hood: How Form validation works - DEV Community
May 25, 2025 - It ensures the form is fully validated before returning the collected errors. If there is no error, the full_clean() method will be called, otherwise it returns self._errors, which is populated by calling add_error() when a validation error ...
Discussions

python - Form validation in django - Stack Overflow
I just started to use django. I came across forms and I need to know which one is the better way to validate a forms. Would it be using django forms or should we use javascript or some client side More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to validate form field in django? - Stack Overflow
I want to make shure that the current value of the bid field is not less than current biggest bid. This is my form with a custom clean method. Form: class Place_A_Bid_Form(forms.Form): listing = More on stackoverflow.com
๐ŸŒ stackoverflow.com
Tutorial: Django Form Validation Guide - Show & Tell - Django Forum
Form validation is an important feature for web applications, and there are many ways to do it. In this tutorial, I will talk about some different ways to do form validation in Django, and compare them to help you choose the best way in your project. After reading this article, you will learn: ... More on forum.djangoproject.com
๐ŸŒ forum.djangoproject.com
1
May 17, 2023
python - Django Form validation overview (quick!) - Stack Overflow
There is reasonably precise documentation about Django Form validation and I have used it successfully already, so what is my problem? My problem is remembering this stuff. The framework involves More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-form-validation-using-django
Form Validation in Django - GeeksforGeeks
November 10, 2025 - Form validation ensures that user-submitted data meets specific requirements before being processed or saved. It can be applied to fields such as username, gender, or text inputs to maintain accuracy and consistency.
๐ŸŒ
Django Documentation
docs.djangoproject.com โ€บ en โ€บ 5.2 โ€บ ref โ€บ validators
Validators | Django documentation | Django
Note that validators will not be run automatically when you save a model, but if you are using a ModelForm, it will run your validators on any fields that are included in your form. See the ModelForm documentation for information on how model validation interacts with forms. The django.core.validators module contains a collection of callable validators for use with model and form fields.
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-to-do-django-form-validation
How to do Django form validation
Django automatically has built-in methods that validate the data from the form.
๐ŸŒ
Medium
medium.com โ€บ @altafkhan_24475 โ€บ part-12-validation-in-django-form-model-form-d72345d44a00
Part-12: Validation In Django Form & Model Form | by Altaf Khan | Medium
July 12, 2024 - For example, Email Field will automatically check if the input is a valid email address ยท from django import forms class StudentForm(forms.Form): email = forms.
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-form-validation-using-django
Python | Form validation using django - GeeksforGeeks
January 23, 2023 - Now a form can be created. Suppose that the username length should not be less than 5 and post length should be greater than 10. Then we define the Class PostForm with the required validation rules as follows: ... from django.forms import ModelForm from django import forms from formValidationApp.models import * # define the class of a form class PostForm(ModelForm): class Meta: # write the name of models for which the form is made model = Post # Custom fields fields =["username", "gender", "text"] # this function will be used for the validation def clean(self): # data from the form is fetched
๐ŸŒ
Javatpoint
javatpoint.com โ€บ django-form-validation
Django Form Validation - javatpoint
Django Form Validation with Introduction, Features, Installation, Environment Setup, Project, Tutorial, Apache Configuration, App, Forms, Form Validation, File Upload etc.
Top answer
1 of 2
4
class Place_A_Bid_Form(forms.Form):
    listing = forms.CharField(widget=forms.TextInput(attrs={"type":"hidden"}))
    bid = forms.IntegerField(widget=forms.NumberInput(attrs={"class":"form-control"}),
    min_value=1)

    def __init__(self,biggestBid=0 *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.biggestBid = biggestBid

    def clean_bid(self):
        bid = self.cleaned_data["bid"]
        if bid < self.biggestBid:
            raise ValidationError("""New bid shouldn't be less than starting bid, or 
                                    if any bids have been placed then new bid 
                                    should be greater than current biggest bid""")
        return bid

and then in views.py:

def place_a_bid(request):
    if request.method == "POST":
        dict = Bid.objects.filter(user=user).aggregate(Max("amount"))
        form = Place_A_Bid_Form(biggestBid=dict['amount__max'], data=request.POST)
        user = User.objects.get(username=request.user.username)
        if form.is_valid():
            data = form.cleaned_data
            user_obj = User.objects.get(username=request.user.username)
            listing_obj = Listing.objects.get(title=data["listing"])
            Bid.objects.update_or_create(
                user=user_obj,
                listing=listing_obj,
                amount=data["bid"]
            )
        return redirect(listing_obj)
2 of 2
0

Django's IntegerField [Django-doc] can validate a minimum value without any extra logic, you can set the .min_value and add a validator with:

from django.core.validators import MinValueValidator

class Place_A_Bid_Form(forms.Form):
    listing = forms.CharField(widget=forms.TextInput(attrs={'type': 'hidden'}))
    bid = forms.IntegerField(widget=forms.NumberInput(attrs={'class':'form-control'}))

    def __init__(self, *args, **kwargs, min_bid=0):
        super().__init__(*args, **kwargs)
        bid = self.fields['bid']
        min_bid += 1
        bid.min_value = min_bid
        bid.validators.add(MinValidator(min_bid))

so then you only need to pass the min_bid to the form:

from django.contrib.auth.decorators import login_required

@login_required
def place_a_bid(request):
    biggest_bid = Bid.objects.filter(user=request.user).aggregate(
        min_bid=Max('amount')
    )['min_bid'] or 0
    if request.method == 'POST':
        form = Place_A_Bid_Form(request.POST, min_bid=biggest_bid)
        if form.is_valid():
            data = form.cleaned_data
            listing_obj = Listing.objects.get(title=data['listing'])
            Bid.objects.update_or_create(
                user=request.user,
                listing=listing_obj,
                amount=data['bid']
            )
            return redirect(listing_obj)
    else:
        form = Place_A_Bid_Form(min_bid=biggest_bid)
    return render(request, 'app_name/name-of-template.html', {'form': form})

This also construct a form in case of a GET request with the biggest bidding as minimum bid. This will also add this as min="biggest-bid" in the HTML so the browser can validate this. This can thus also validate the bid already at client side before submitting the form, but will also properly validate the form at the server side.

It might however be better to pass the listing not through the form, but as a URL parameter.


Note: You can limit views to a view to authenticated users with the @login_required decorator [Django-doc].

๐ŸŒ
Django Forum
forum.djangoproject.com โ€บ show & tell
Tutorial: Django Form Validation Guide - Show & Tell - Django Forum
May 17, 2023 - Form validation is an important feature for web applications, and there are many ways to do it. In this tutorial, I will talk about some different ways to do form validation in Django, and compare them to help you choose the best way in your project. After reading this article, you will learn: What is Built-in Form Validation in HTML How to use Javascript to do client form validation How to use jQuery Validation or Parsley to do client form validation, and how they work How to use Yup to do ...
๐ŸŒ
Python Guides
pythonguides.com โ€บ django-form-validation
Python Django Form Validation
July 24, 2025 - Form validation is the process of ensuring that the data users submit through forms meets the criteria your application expects. This includes checking required fields, data types, length, format, and even complex business rules.
๐ŸŒ
AbstractAPI
abstractapi.com โ€บ api guides, tips & tricks โ€บ django form validation: how to validate forms with django (2023)
Django Form Validation: How to Validate Forms with Django (2023)
June 7, 2024 - As you can see, the Django forms class gives us a lot of useful stuff. We can define a name input field as a CharField that accepts characters, and define our email input as an EmailField. This will be useful later when we want to do email validation.
๐ŸŒ
DataFlair
data-flair.training โ€บ blogs โ€บ django-forms-handling-and-validation
Django Forms Handling & Django Form Validation - Master the Concept - DataFlair
June 21, 2021 - With this Django forms tutorial, learn the concept of forms, GET and POST method, HTML forms, Django form handing, Django form validation and class.
๐ŸŒ
Readthedocs
django-jsonform.readthedocs.io โ€บ en โ€บ latest โ€บ guide โ€บ validation.html
Validation โ€” django-jsonform documentation - Read the Docs
# models.py class ShoppingList(models.Model): items = JSONField(schema=...) ... # admin.py class ShoppingListForm(forms.ModelForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # set your validators on the form field self.fields['items'].validators = [items_validator] class ShoppingListAdmin(admin.ModelAdmin): form = ShoppingListForm ยท In your validator function, instead of raising ValidationError you must raise JSONSchemaValidationError. This exception allows you to pass error messages for individual input field in the widget. Weโ€™ll use the ErrorMap helper class t
๐ŸŒ
Horilla
horilla.com โ€บ blogs โ€บ how-to-validate-forms-with-django
How to Validate Forms With Django in 2023 | Blogs | Free HRMS | Horilla
August 8, 2023 - By implementing these methods in a form class, developers can perform custom validation logic at both the form level and individual field level, respectively. Hereโ€™s an example that demonstrates the usage of the clean() method and clean_<field_name>() methods: from django import forms class ContactForm(forms.Form): name = forms.CharField(max_length=100) email = forms.EmailField() message = forms.CharField(widget=forms.Textarea) def clean_message(self): message = self.cleaned_data['message'] if 'spam' in message: raise forms.ValidationError("Your message contains spam words.") return message def clean(self): cleaned_data = super().clean() name = cleaned_data.get('name') email = cleaned_data.get('email') # Custom form-level validation logic if name and email: if not name.isalpha() or not email.endswith('@example.com'): raise forms.ValidationError("Invalid name or email.")
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ form-validation-using-django
Form validation using Django
November 13, 2020 - from django.shortcuts import render from django.http import HttpResponse from .forms import UserForm # Create your views here. def home_view(request): # cheking the request if request.method == 'POST': # passing the form data to LoginForm user_details = UserForm(request.POST) # validating the user_details with is_valid() method if user_details.is_valid(): # writing data to the database user_details.save() # redirect to another page with success message return HttpResponse("Data submitted successfully") else: # redirect back to the user page with errors return render(request, 'validation/home.html', {'form':user_details}) else: # in case of GET request form = UserForm(None) return render(request, 'validation/home.html', {'form':form})
๐ŸŒ
Byteacademy
byteacademy.co โ€บ blog โ€บ validating-form-input-with-django
Validating Form Input With Django
With this strategy, Iโ€™ve added ... If you have form input that youโ€™d like to check in some way, two options you have are to place your validators on the model or on the form....
๐ŸŒ
Saashammer
saashammer.com โ€บ blog โ€บ django-form-validation-guide
Django Form Validation Guide | SaaS Hammer
User needs to submit the form to server to get the validation error messages. The Django REST framework Serializer is very similar with the Django Form, we can use it convert data to Python primitive types, and validate the data.
Top answer
1 of 1
12

Assume you have a Form class MyForm with an instance called myform and containing various Fields, in particular a SomeField field called somefield which we use as an example to understand what is going on. SomeField can be from Django or your own code.

The Form validation process

These are the validation steps that Django is going to perform or attempt:

  1. SomeField.to_python(self, value)

    • called for: each Field of myform
    • meaning: converts the string value to its Python target type (e.g. int)
    • takes input from: value
    • returns: value coerced into the proper Python type for SomeField
    • side effects: should have none
    • signals problems by: raise ValidationError
  2. SomeField.validate(self, value)

    • called for: each Field of myform
    • meaning: validates Field locally (just like a validator would)
    • takes input from: value
    • returns: None
    • side effects: should have none
    • signals problems by: raise ValidationError
  3. SomeField.run_validators(self, value)

    • called for: each Field of myform
    • meaning: executes all validators registered for myform.somefield
    • takes input from: value
    • returns: None
    • side effects: should have none
    • signals problems by: raise ValidationError combining all ValidationErrors from the validators into one
  4. SomeField.clean(self, value)

    • called for: each Field of myform
    • meaning: runs to_python, validate, and run_validators
    • takes input from: value
    • returns: the desired ("cleaned") value, usually the result of to_python
    • side effects: Django will insert the return value into myform.cleaned_data
    • signals problems by: not handling any ValidationError raised by the other operations
    • note: do not override.
  5. MyForm.clean_somefield(self)

    • called for: each Field of myform with such a method
    • meaning: validate somefield locally
    • takes input from: self.cleaned_data (no longer just strings now!)
    • returns: the new or unchanged value for somefield
    • side effects: Django will insert the return value into myform.cleaned_data
    • signals problems by: raising ValidationError
    • note: This happens in the same loop as the Field.clean calls.
  6. MyForm.clean(self)

    • called for: myform once
    • meaning: perform any cross-field validation
    • takes input from: self.cleaned_data (no longer just strings now!)
    • returns: either None or a dict that will become cleaned_data
    • side effects: Django will assign a dict return value to myform.cleaned_data
    • signals problems by: calling self.add_error or raising ValidationError. The latter will end up in myform.non_field_errors().
    • note: Beware when accessing cleaned_data, as fields that did not validate will be missing.

Extensions for ModelForms

Validation of a ModelForm has one more step added at the end:

  1. myform.instance.full_clean(): calling validation on the respective model instance (if any).

And a ModelForm's clean method will also have access to the model instance via this instance attribute.

Customizing validation

For making myform validate just like you want, you therefore have different possibilities:

  • At the SomeField class level, you can override SomeField.to_python or SomeField.validate (e.g. by subclassing)
  • For field-level validation at the MyForm class level, you can implement MyForm.clean_somefield or just register a validator: somefield = SomeField(validators=[somevalidator]).
    • That validator can be a standard one from django.core.validators or a custom one.
    • BTW: You can place a validator function into your Form class; simply refrain from adding self as the first parameter.
  • At the MyForm level, you can implement MyForm.clean.

Triggering validation

This validation process can be triggered in various ways:

  • calling myform.full_clean()
  • calling myform.is_valid()
  • accessing myform.errors etc.