How to add css in django Updateview or Create view form

Tags: python,css,django,django-forms,django-views

Problem :

I am working on a project, and my designer gave me the design, so I want to mimic the input forms which are in the design, to do that I need to add css in my form object.

If in the case of django function based view, It is easy to addcss by creating files and add css as follows. adding css class in django forms

I also tried to inject css class using jquery, but I couldn't succed. Injecting css class in html forms element using jquery


But how do I add custom css in the form field, when using class based view.

class ItemUpdateView(UpdateView):
    model = Item
    fields = ('name','tag', 'category', 'company', 'price',)

How do I add the custom class to name, tag, category field.

Solution :

You can define form_class attribute on your update view and add css to that form.

class ItemUpdateView(UpdateView):
    form_class = ItemForm

ItemForm can be a ModelForm and you can customize it as described here:

    CSS Howto..

    How to target content through css

    How to make permanent changes to a website's CSS from within the browser?

    How to add CSS stylesheet to aspx.vb table

    How can I fix the indentation in a facebook like-box?

    How to display the the full content of a database on clicking on 'Read More' button

    How to make a wavy border line to separate background images in html5/css?

    Show required asterisk star after the text?

    How to load self hosted font files if the GoogleFont service is unavailable?

    how to make css :after / :before content clickable on a label element [duplicate]

    How to force div width with CSS to stretch to its content but not to be restricted by its container?

    How to move text list items to align with an image list item

    How to scale and center text vertically in a fluid layout? (using CSS)

    How to have several equal sized div blocks take 100% of a parent container

    How to make footer invisible on making screen size smaller?

    How to Align a Link HTML/CSS

    How would can i keep horizontal divs (3 in a row) with margins inbetween them inline with wrapper?

    How do I get nested divs to be same height and expand to the largest of the heights?

    How to align text vertically

    how can css reset :hover to default state?

    How to select a child element in CSS?

    How to make text with certain id show up after hovering over a certain image

    How to set the color to the user's link color in CSS?

    Need the background to change when the mouse goes over the selected tab. How?

    How can I incorporate a slideshow into HTML?

    How can I use symbol fonts like marvosym in the browser?

    in Emacs, how to turn off abbrevs in css-mode?

    I can't figure out how to get display property to work when it comes to multiple div elements

    how to get 2 div's text to align along the bottom?

    How do I add custom fonts? [duplicate]

    How to prevent division when using variables separated by a slash in CSS property values