I have a question on Django, I created my registration form, here is my template:
<h2>Register</h2>
<form action="/register/" method="post" id="register">
{% csrf_token %}
{{form}}
<input type="submit" value="Register"/>
</form>
I have 4 Fields : Username, Password1, Password2, Email
The display on my html page is In this Order -> Password1, Username, Password2, Email
What I want -> Username, Email, Password1, Password2
How can I change the display order of my inputs ?
Normally you have a form class and the ordering of the fields in this class should define the ordering in the output. So you have to look there.
When you can't change the form class or don't want to, you can render the fields manually inside your template for example:
<h2>Register</h2>
<form action="/register/" method="post" id="register">
{% csrf_token %}
<div class="fieldWrapper">
{{ form.Username.errors }}
{{ form.Username.label_tag }}
{{ form.Username }}
</div>
<div class="fieldWrapper">
{{ form.Email.errors }}
{{ form.Email.label_tag }}
{{ form.Email }}
</div>
<div class="fieldWrapper">
{{ form.Password1.errors }}
{{ form.Password1.label_tag }}
{{ form.Password1 }}
</div>
<div class="fieldWrapper">
{{ form.Password2.errors }}
{{ form.Password2.label_tag }}
{{ form.Password2 }}
</div>
<input type="submit" value="Register"/>
</form>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.