Disable Form Fields
A snippet showing how to disable form fields in Django.
# forms.py
from django import forms
class ProfileForm(forms.Form):
email = forms.EmailField()
plan = forms.CharField()
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Disable email (read-only display in form)
self.fields["email"].disabled = True
Explanation:
-
Use
field.disabled = True(preferred) rather than HTML-onlyreadonly. -
Disabled fields are excluded from validation and
cleaned_data.
- Category Forms & Validation
- Total Views 859
- Last Modified 14 November, 2025
- Tags #forms #ui #disabled #fields
Previous snippet
Required vs Optional Fields
Next snippet