You can put it in the form class as follows:
class MyForm(forms.Form): MY_VALUE = 'SOMETHING' myfield = forms.CharField( initial=MY_VALUE, widget=forms.TextInput(attrs={'disabled': 'disabled'}) def __init__(self, *args, **kwargs):
How it works, checks to see if any data has been passed to the form constructor. If it does, it copies it (the raw data is unchanged), and then puts the initial value in the value before continuing to instantiate the form.
seddonym
source share