I am trying to create my Django file upload button , but since it is processed through a form and is clearly not written in HTML in the template, I cannot erase it directly from other input buttons of the type from HTML and CSS.
I tried adding my CSS class to my forms.py , but it placed the default Django file upload button located on top of my stylized CSS button.
My code is as follows:
class FileUploadForm(forms.Form): docFile = forms.FileField( label = "Select a CSV file", ) class Meta: model = FileUpload fields = ('docFile') def __init__(self, *args, **kwargs): super(FileUploadForm, self).__init__(*args, **kwargs) self.fields['docFile'].widget.attrs.update({'class': 'my_class'})
I also tried defining a widget in my Meta class as follows:
class Meta: model = FileUpload widgets = { 'docFile': forms.FileInput(attrs={'class': 'my_class'}), }
but it was like my first attempt.
Is there any other way to accomplish this, or are there some logical errors you might find in my code?
source share