[PYTHON] A note that you want to manually decorate the parameters passed in the Django template form item by item

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. image.png

When I actually run server and look at the HTML source, it looks like this.

image.png 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. image.png

It seems that you can decorate each item with this.

Recommended Posts

A note that you want to manually decorate the parameters passed in the Django template form item by item
If you want to display values using choices in a template in a Django model
Make a note of what you want to do in the future with Raspberry Pi
I want to use complicated four arithmetic operations in the IF statement of the Django template! → Use a custom template
I want to create an API that returns a model with a recursive relationship in the Django REST Framework
[Django memo] I want to set the login user information in the form in advance
Handle CSV that contains the element you want to parse in the file name
How to count the number of elements in Django and output to a template
Solution to the problem that you can't activate by putting conda in pyenv
[Django] Create a form that automatically fills in the address from the zip code
It's okay to participate for the first time! A hackathon starter kit that you want to prepare "before" participating in the hackathon!
Set the form DateField to type = date in Django
DJango Note: From the beginning (creating a view from a template)
When you want to plt.save in a for statement
How to create a record by pasting a relation to the inheriting source Model in the Model inherited by Django
A story that makes it easier to see Model debugging in the Django + SQLAlchemy environment
How to generate a query using the IN operator in Django
[Django] What to do if the model you want to create has a large number of fields
"The Cathedral and the Bazaar" that only those who work in a solid company want to read
I want to manually assign the training parameters of the [Pytorch] model
Don't you want to say that you made a face recognition program?
If you want to assign csv export to a variable in python
When you want to sort a multidimensional list by multiple lines
[python] A note that started to understand the behavior of matplotlib.pyplot
I want to be healed by Mia Nanasawa's image. In such a case, hit the Twitter API ♪
Memorandum Regular expression When there are multiple characters in the character string that you want to separate
A super introduction to Django by Python beginners! Part 3 I tried using the template file inheritance function
If you want to switch the execution user in the middle of a Fabric task, settings context manager
A super introduction to Django by Python beginners! Part 2 I tried using the convenient functions of the template
[AtCoder for beginners] A story about the amount of calculation that you want to know very roughly
I want to change the color by clicking the scatter point in matplotlib
If you want a singleton in python, think of the module as a singleton
Note: [Python3] Convert datetime to a string in any format you like
When you want to replace a column with a missing value (NaN) column by column
Python Note: When you want to know the attributes of an object
I want to sort a list in the order of other lists
I want to use the Django Debug Toolbar in my Ajax application
Added a function to register desired shifts in the Django shift table
I want to identify the alert email. --Is that x a wildcard? ---
How to sort by specifying a column in the Python Numpy array.
[Python3] Code that can be used when you want to cut out an image in a specific size