Menu Close

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

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 .

Posted in Python, Python Answers