0

I have a django form where I have certain fields. Now I want to add some styling to it (bootstrap mostly). But it does not seem to be working.

In my forms.py file

from django import forms
from django.core.validators import FileExtensionValidator

file_type_choices = [
    ('CSV', 'Comma-Separated Values'),
    ('TSV', 'Tab-Separated Values')
]

valid_extensions = ['.tsv', '.csv']

class FileUploadForm(forms.Form):
    file = forms.FileField(allow_empty_file=False, \
                           validators=[FileExtensionValidator(allowed_extensions=valid_extensions)])
    file_type = forms.ChoiceField(choices=file_type_choices, widget=forms.Select(attrs={"class": "form-control"}))
    source_language = forms.CharField(max_length=30,\
                                      widget=forms.TextInput(attrs={"class":"form-control", "placeholder": "English"}))
    target_language = forms.CharField(max_length=30, \
                                      widget=forms.TextInput(attrs={"class":"form-control"}))

I also added bootstrap CDN links in the templates. And just for surety, added the following in settings.py file of the project: python CRISPY_TEMPLATE_PACK = 'bootstrap5' Also, its curious to see that placeholder is also not working. I don't see particular reason behind this.

  • Try [force-reloading](https://stackoverflow.com/q/118884/494134) the page. It could be that your browser is caching an older version of the css file. – John Gordon Mar 25 '23 at 17:00

1 Answers1

0

Try this package, it helps you to add class to the form fields

Django-wedget-tweaks

Byansi
  • 37
  • 7