matts1
matts1

Reputation: 865

Create template for forms django

I currently have a login.html, which has inside it a form for login. All my forms need to look similar, however will have different content. At the moment my code for it looks like this:

<form enctype="multipart/form-data" method="POST" action="">
    <fieldset>
        <legend>{{ legend }}</legend>
        <div style="line-height:18px">{% block top %}{% endblock %}<br></div>
        <table class="form">
        {% for text,name,inputtype in formcontent %}
            <tr>
                <td class="right">
                    <label>{{ text }}:</label><br/>
                </td><td style="float:left">
                    <input name="{{ name }}" type="{{inputtype}}">
                </td>
            </tr>
        {% endfor %}
        </table>
    <input value="{{ button }}" type="submit">
    <div style="line-height:18px">
        <div class="err">
            {{ err }}
        </div>
        {{ bottom }}
    </div>
</fieldset></form>

I was wondering if there was a better way to do it than to put variables into my urls.py (given that there may be multiple forms on hte page, I don't believe that this would work under all circumstances). A nice solution would be to create a class, but I don't know how to call this class from a page. I know it would involve making a tag, but I don't see how you can provide a 2d array as an argument from a template.

Upvotes: 0

Views: 243

Answers (1)

miki725
miki725

Reputation: 27861

Django Crispy Forms were made for this exact reason. I think they are exactly what you need.

Upvotes: 1

Related Questions