[Answer]-How to customize a django form (adding multiple columns)

1👍

You can customize the form HTML using its fields, as shown in the documentation. You are doing this in an unusual way; normally you would have the template in a file instead of returning it from a function, but you can still do this:

from django.template import Context

def getdjtemplate():
    dj_template = """
    <table>
        {% for field in form %}
        <tr>{{ field }}</tr>
        {% endfor %}
        </table>
        """
    return dj_template

form = old_form()
djtemplate = getdjtemplate()
newtmpl = Template(djtemplate)
c = Context({'form': form})
newtmpl.render(c)

Leave a comment