DEV Community

Nikhil Chandra Roy
Nikhil Chandra Roy

Posted on

Django custom html class in form easy way.

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/

Top comments (0)