0

I am using boostrap forms but I need to customize it in my design. When I simply write

    <form class="firstform" method="POST" enctype="multipart/form-data">
    {% csrf_token %}
    {% bootstrap_form form %}

its showing nice form but I want to edit this form as my design what can be the best way to do so?

2 Answers 2

1

Use the Django widget tweaks. It’s the best way to decorate and modify your templates in django. https://pypi.org/project/django-widget-tweaks/

You could add attributes, classes etc.

For instance if you would like to insert an input inside your form please add

{% load widget_tweaks %}

{{ form.title|add_class:"css_class_1 css_class_2" }}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for reply, would you tell me how can I show error with widget-tweaks as I was getting it with boostrap forms ?
0

You can use django widget tweaks. This is what I am currently using. After installing them usingpip install django-widget-tweaks, and adding to installed_apps, load them using

{% load widget_tweaks %}

in you template and use them like:

{% render_field form.some_field | attr:"autfocus" class+="class1 class2" %}

which will add attribute 'autofocus' and classes 'class1' and 'class2'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.