Python 3.8.5 Django version 3.1.2
memorandum
/formtest/formman$ tree
.
├── admin.py
├── apps.py
├── forms.py ★ I made it.
├── __init__.py
├── migrations
│ ├── 0001_initial.py
│ ├── 0002_auto_20201119_1155.py
│ └── __init__.py
├── models.py ★ I wrote
├── templates ★ Made
│ ├── base.html
│ └── formman
│ └── form.html
├── tests.py
└── views.py ★ I wrote
3 directories, 12 files
If you read Django's tutorials and references It says that Django's View will display the form item in the Template if you write it for the following.
{{ form.as_p }}
I write like this.
When I actually run server and look at the HTML source, it looks like this.
That means that the following part corresponds to form.as_p
.
<p><label for="id_id">ID:</label> <input type="number" name="id" required id="id_id"></p>
<p><label for="id_name">Name:</label> <input type="text" name="name" maxlength="100" required id="id_name"></p>
<p><label for="id_number">value:</label> <input type="number" name="number" required id="id_number"></p>
If you rewrite form.as_p
as follows ...
{{ form.id.label }}
{{ form.name.label }}
{{ form.number.label }}
{{ form.id }}
{{ form.name }}
{{ form.number }}
Oh. It went well.
It seems that you can decorate each item with this.
Recommended Posts