How can I add attrs to image in the code given below

Viewed 17
    widgets = {
        'img':forms.ImageInput(attrs={'class':'box'}), 
        'title':forms.TextInput(attrs={'class':'box'}), 
        'title':forms.TextInput(attrs={'class':'box'}),
        'title':forms.TextInput(attrs={'class':'box'}),
    }

'img':forms.ImageInput(attrs={'class':'box'}), this line gives me error.

1 Answers

The widget for ImageField is FileInput not ImageInput, django has no widget called ImageInput...

Try this code

'img':forms.FileInput(attrs={'class': 'box'}),
Related