Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reorder form elements and change labels on django password change form

I'm still relatively new to Django and I've managed to set up a password change form using my template. I don't know how to change the order and labels for the elements. I have attached an image showing how the form currently looks, I would like to move the second text box (new password) underneath the explanation text and to change the first and last input labels.

Could you please point me in the right direction?

current view

like image 227
Alex Avatar asked Jan 01 '26 10:01

Alex


1 Answers

I can't help more without your template code but. From the django Render Fields docs.

We don’t have to let Django unpack the form’s fields; we can do it manually if we like (allowing us to reorder the fields, for example). Each field is available as an attribute of the form using {{ form.name_of_field }}, and in a Django template, will be rendered appropriately.

{{ form.non_field_errors }}
<div class="fieldWrapper">
    {{ form.subject.errors }}
    <label for="{{ form.subject.id_for_label }}">Email subject:</label>
    {{ form.subject }}
</div>
<div class="fieldWrapper">
    {{ form.message.errors }}
    <label for="{{ form.message.id_for_label }}">Your message:</label>
    {{ form.message }}
</div>
<div class="fieldWrapper">
    {{ form.sender.errors }}
    <label for="{{ form.sender.id_for_label }}">Your email address:</label>
    {{ form.sender }}
</div>
<div class="fieldWrapper">
    {{ form.cc_myself.errors }}
    <label for="{{ form.cc_myself.id_for_label }}">CC yourself?</label>
    {{ form.cc_myself }}
</div>
like image 161
Gytree Avatar answered Jan 02 '26 22:01

Gytree



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!