Skip to content
Advertisement

Add custom CSS styling to model form django

I am using a bootstrap variant to help style a model form. There is a certain class I would like one of the fields to be and I have read around on the subject and the general consensus is to add a widget to the ModelForm’s meta, like I tried below:

forms.py

JavaScript

However this doesn’t seem to render onto my template, which is:

JavaScript

Is there another way to do this or is there something I have done wrong in my code?

UPDATE I have followed the suggested of Jacek and now it is styled but the information is no longer displaying, this is my new code:

forms.py:

JavaScript

views.py:

JavaScript

html:

JavaScript

Advertisement

Answer

Try this:

forms.py

JavaScript

view.py

JavaScript

yourview.html

JavaScript
Advertisement