I'm sorry for the continuous throwing. I wanted to fill the calendar ...
I've been writing all about Form,
I'm writing about
ModelForm.field_order
A field called field_order
in Model Form? there is.
This is a field that literally sets the order of the fields.
forms.py
class MyForm(ModelForm):
field_order = ["name", "age", "address", ]
If you do, the order of the fields will be set. If you want to decide only the first field, you can write only that field. The rest is determined by Django.
that way,
form.html
<form method="post">
{% csrf_token %}
{{ form }}
<button type="submit">
</form>
Even when you do like this, the order will be as you like.
crispy form
I often use Twitter Bootstrap, but I can't specify the CSS class
in{{form}}
.
In that case, use the cripsy form.
pip install django-crispy-forms
You can enter with this.
After that, in settings.py
settings.py
INSTALLED_APPS += ('crispy_forms', )
CRISPY_TEMPLATE_PACK = 'bootstrap3'
As in the template
form.html
{% load crispy_forms_tags %}
<form method="post">
{% csrf_token %}
{{ form|crispy }}
<button class="btn btn-primary" type="submit">
</form>
If so, it's strange. It will be a properly styled form.
See the documentation for more details.
Also, there was a crispy form screencast in GoDjango, so I'll put a link here. I use it a little deeper than the one I introduced.
If you use the order of the fields I wrote at the beginning and the crispy form, the layout of the form will be much easier.
Especially the crispy form is a recommended module because it can do a lot of things.
I'm out of material.
Recommended Posts