[Fixed]-Django form template customization

1👍

Using a custom widget as suggested in the comment is one option, another is to loop through the fields manually.

<form action="/your-name/" method="post">
    {% csrf_token %}
    {{ form.non_field_errors }}
    {% for field in form %}

        <div class="fieldWrapper">
            {{ field.errors }}
            {{ field.label_tag }} {{ field }}
            {% if field.help_text %}
                  <p class="help">{{ field.help_text|safe }}</p>
            {% endif %}

            {% if field.id_label = id_currentWeightKg" %}
                <span class="customCss">Kg (or text I enter</span>
            {% endif %}
        </div>
    {% endfor %}
    <input type="submit" value="Submit" />
</form>

For additional information refer to the Looping over form fields section in the manual.

before you do this, view the HTML source and confirm that id_currentWeightKg is the correct id for the field in question. If not use replace with the correct one.

👤e4c5

Leave a comment