Django modelform and CSS styling

A

I'm using modelforms to generate forms.

wiek = models.PositiveIntegerField(verbose_name="Wiek")

Is there a way to assign CSS style to it? I don't want to create html for forms because it is too much work (complex forms). I want to generate them from models, but I want to style it too. How to create seperate CSS for each form?

Thanks for answer in advance

Q

Well,

option 1:

probably you have code like this:

If so, you can assign some special class to each tag and than style it as you want.

option2(个人觉得比较简单的做法)

if you need to style each field independently you can use fact that Django by default uses id_name_of_field conevention to name fields ids. So you can use #id_name_of_field in your css to style particular field.

option3

in model form you can assign some attributes to each field's widget like:

self.fields['wiek'].widget.attrs['class'] = 'some-class'

你可能感兴趣的:(Django modelform and CSS styling)