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 forms.py 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

myapp/forms.py

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: https://docs.djangoproject.com/es/1.9/topics/forms/modelforms/#overriding-the-default-fields


    CSS Howto..

    How do I submit suggestions to the CSS spec? [closed]

    How to avoid the pain of CSS multi-browser compatibility?

    How to fix an overlapping image in CSS?

    How can you have your websites resolution change according to the users screen resolution?

    How can I toggle a div to reveal content with CSS

    How to do navbar fixed?

    make a div fold out to show content

    How to remove that ugly border in my link with a background image?

    How to make the parent div adjust in size to contain the CSS-Rotated child div?

    How do I apply css to only IE 8 and below

    How can I write a complex fraction using HTML/CSS/jQuery?

    Hiding the content of a
    and showing another
    with different contents

    How to style a built-in comment box imported from a third party?

    @font-face font working fine locally but when pushed to server it just shows up as a default HTML font

    How to run a different html file when device width changes?

    How to apply css for anchor tag inside table

    Error: Dynamically fetching css from CDN with fallback to local copy, How to resolve?

    How to specify a flex item to be of certain minimum width?

    How to use CSS for mobile in the right way?

    How to add load more button for a HTML/CSS page?

    How to add all li of existing ul to the bottom of another ul base on their css classes

    How to add + and - to my menu tabs [closed]

    Show nav once the nav has been hidden

    How do I style forms using CSS

    How can I style this php with divs?

    How to draw a specific shape in CSS? [closed]

    How to automatically put DIVs in columns (unknown number of DIVs)

    How do you associate a css/sass stylesheet to a view in rails?

    How to place two divs next to each other?

    How do I install and use Groundwork CSS