[PYTHON] Forms in Django

Introduction

Here's the basics of setting up forms in django.

Add forms.py

forms.py


from django import forms

from .models import SampleModel


class SampleForm(forms.ModelForm):

    char_sample = forms.CharField(widget=forms.TextInput(attrs={'size': 300}))

    class Meta:
        model = SampleModel
        fields = ('char_sample', 'text_sample')

By setting the form class, you can make more detailed settings for the form set in the model. In the Meta class, specify the target model and the fields to be displayed.

Summary

Here, we've covered setting up Django form classes. Next time I'll cover views.

Recommended Posts

Forms in Django
Models in Django
Model changes in Django
Performance optimization in Django 3.xx
PHP var_dump in Django templates
Handle constants in Django templates
Implement follow functionality in Django
Rename table columns in Django3
Output table structure in Django
Django
Show Django ManyToManyField in Template
Implementing Add Form Buttons in Django Inline Forms Set Part2
reload in django shell with ipython
Set placeholders in input fields in Django
8 Frequently Used Commands in Python Django
Dynamically add form fields in Django
Errors related to memcached in django
Implementation of login function in Django
Register your Django application in your project
Write foreign key constraints in Django
How to reflect CSS in Django
Switch the language displayed in Django 1.9
Get parameter values ​​in Django templates
The meaning of ".object" in Django
Deploy Django in 3 minutes using docker-compose
Like button implementation in Django + Ajax
Get the query string (query string) in Django
Create a LINE Bot in Django
Install Django in a pipenv virtual environment
django update
Django note 4
Get the client's IP address in Django
When you can't call base.html in Django
Django: Migration doesn't reflect model in DB
Logical deletion in Django, DRF (Django REST Framework)
Django memorandum
What's new in Django 1.8 Conditional Expressions #djangoja
django search
Django installation
Django Summary
Django test
Information recording memo using session in Django
How to delete expired sessions in Django
CSS environment created in 10 minutes using Django
Notes on creating static files in Django
Same-Site attribute setting for cookies in Django
Django # 2 (template)
(Note) Template file search order in Django
Django Note 5
Django hands-on
django notes
Django Summary
Django basics
Django Shoho
Dynamically specify a ModelChoiceField queryset in Django
Get query parameters for GET requests in Django
Django defaults
Django + Docker
Ajax in Django (using generic class view)
Hello world instead of localhost in Django
Django search