Categories
Python Answers

How to add a form to a dynamically to a Django formset?

Spread the love

To add a form to a dynamically to a Django formset, we can use a for loop.

For instance, we write

<h3>My Services</h3>
{{ serviceFormset.management_form }}
{% for form in serviceFormset.forms %}
    <div class='table'>
    <table class='no_error'>
        {{ form.as_table }}
    </table>
    </div>
{% endfor %}
<input type="button" value="Add More" id="add_more">

to render the forms with form.as_table within the for loop.

We get the forms from serviceFormset.forms .

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *