DEV Community

loading...

Django custom html class in form easy way.

nikhilroy2 profile image Nikhil Chandra Roy ・1 min read

I have spent so much time to do it, just got quick way installing

pip install django-widget-tweaks 
Enter fullscreen mode Exit fullscreen mode

after install it we have to put it in settings

INSTALLED_APPS =[
      'widget_tweaks',

]
Enter fullscreen mode Exit fullscreen mode

and in html

{% load widget_tweaks %}

{% for r in register %}
<div class="form-group mb-2">
    <label for="" class="form-label">{{r.label}}</label>
    {{r|add_class:"form-control"}}
</div>

{% endfor %}

Enter fullscreen mode Exit fullscreen mode

that's enough.
for more details about it https://pypi.org/project/django-widget-tweaks/

Discussion (0)

Forem Open with the Forem app