When attempting to apply CSS to form.ImageField in Django similar to CharField, I encountered an error.
File "/Users/hogehoge/Desktop/hoge/hoge/forms.py", line 42, in PostForm
photo = forms.ImageField(label='Image', validators=[file_size],widget=forms.ImageField(attrs={'class': 'fileinput'}))
File "/Users/hoge/opt/anaconda3/lib/python3.8/site-packages/django/forms/fields.py", line 545, in __init__
super().__init__(**kwargs)
TypeError: __init__() got an unexpected keyword argument 'attrs'
Is there a way to apply CSS on form.ImageField?
forms.py
photo = forms.ImageField(label='Image', validators=[file_size],widget=forms.ImageField(attrs={'class': 'fileinput'}))
html
<div class="col-8 col-lg-4">{{ form.photo }}</div>