Django Form | Data Types and Fields
Last Updated :
02 May, 2025
When gathering user information to store in a database, we employ Django forms. Django offers a variety of model field forms for different uses, and these fields have a variety of patterns. The fact that Django forms can handle the fundamentals of form construction in just a few lines of code is their most crucial feature. Although the developer has the option of starting from scratch to design a form, using the Django model form, which manages the fundamental aspects of a user form, is much simpler.
Understanding Django forms is important for building dynamic web applications. To master form handling and other Django functionalities, you can check Django Web Development Course.
These fundamental components consist of designing the form, customizing the form, receiving user data, validating the form, and saving the data in a database.
A checkbox field called a BooleanField in Django Forms stores either True or False. It is used to collect user-provided boolean inputs. CheckboxInput is the default widget for this input. It is converted to a True or False value in Python.
Syntax
field_name = forms.BooleanField(**options)
A string field for small to large-sized strings is called CharField in Django Forms. It is used to collect user-provided text input. This input's default widget is TextInput. If max_length and min_length are supplied, it uses MaxLengthValidator and MinLengthValidator. If not, all inputs are acceptable.
Syntax
field_name = forms.CharField(**options)
A string field called ChoiceField is used in Django Forms to select one option from a list of available options. It is used to implement fields similar to States, Countries, etc., for which information has already been specified and the user must make a selection. It is used to collect user-provided text input. Select is the default widget for this input.
Syntax
field_name = forms.ChoiceField(**options)
DateField in Django Forms is a date field, for taking input of dates from the user. The default widget for this input is DateInput.
Syntax
field_name = forms.DateField(**options)
DateTimeField in Django Forms is a date field, for taking input of date and time from the user. The default widget for this input is DateTimeInput.
Syntax
field_name = forms.DateTimeField(**options)
DecimalField in Django Forms is a decimal field, for input of decimal numbers. The default widget for this input is NumberInput.
Syntax
field_name = forms.DecimalField(**options)
DurationField in Django Forms is used for input of particular durations for example from 12 am to 1 pm. The default widget for this input is TextInput.
Syntax
field_name = forms.DurationField(**options)
EmailField in Django Forms is a string field, for input of Emails. It is used for taking text inputs from the user. The default widget for this input is EmailInput.
Syntax
field_name = forms.EmailField(**options)
FileField in Django Forms is an input field for the upload of files. The default widget for this input is ClearableFileInput.
Syntax
field_name = forms.FileField(**options)
FilePathField in Django Forms is a string field, for the input of the path of a particular file from the server. It is used to select inputs from the user. One needs to specify which folders should be used in FilePathField and the field displays the inputs in the form of a select field. The default widget for this input is Select.
Syntax
field_name = forms.FilePathField(**options)
FloatField in Django Forms is an integer field, for taking input of floating point numbers from the user. The default widget for this input is NumberInput.
Syntax
field_name = forms.FloatField(**options)
GenericIPAddressField in Django Forms is a text field, for input of IP Addresses. It is a field containing either an IPv4 or an IPv6 address. The default widget for this input is TextInput.
Syntax
field_name = forms.GenericIPAddressField(**options)
ImageField in Django Forms is an input field for the upload of image files. The default widget for this input is ClearableFileInput.
Syntax
field_name = forms.ImageField(**options)
IntegerField in Django Forms is an integer field, for the input of Integer numbers. The default widget for this input is NumberInput.
Syntax
field_name = forms.IntegerField(**options)
MultipleChoiceField in Django Forms is a Choice field, for input of multiple pairs of values from a field. The default widget for this input is SelectMultiple.
Syntax
field_name = forms.MultipleChoiceField(**options)
NullBooleanField in Django Forms is a select field that stores either True or False. It is used for taking boolean inputs from the user. The default widget for this input is NullBooleanSelect.
Syntax
field_name = forms.NullBooleanField(**options)
RegexField in Django Forms is a string field, for small- to large-sized strings that one can match with a particular regular expression. It is used for taking selected text inputs from the user. The default widget for this input is TextInput.
Syntax
field_name = forms.RegexField(**options)
SlugField in Django Forms is a slug field, for input of slugs for particular URLs or similar. This field is intended for use in representing a model SlugField in forms. The default widget for this input is TextInput.
Syntax
field_name = forms.SlugField(**options)
TimeField in Django Forms is a time input field, for input of time for a particular instance or similar. The default widget for this input is TimeInput.
Syntax
field_name = forms.TimeField(**options)
TypedChoiceField in Django Forms is a field just like ChoiceField, for selecting a particular choice out of a list of available choices. It is used to implement State, Countries etc. like fields for which information is already defined and the user has to choose one. It is used for taking text inputs from the user. The default widget for this input is Select.
Syntax
field_name = forms.TypedChoiceField(**options)
TypedMultipleChoiceField in Django Forms is a Choice field, for input of multiple pairs of values from a field and it includes a coerce function also to convert data into specific data types. The default widget for this input is SelectMultiple.
Syntax
field_name = forms.TypedMultipleChoiceField(**options)
URLField in Django Forms is a URL field, for the input of URLs from a user. This field is intended for use in representing a model URLField in forms. The default widget for this input is URLInput. It uses URLValidator to validate that the given value is a valid URL.
Syntax
field_name = forms.URLField(**options)
UUIDField in Django Forms is a UUID field, for the input of UUIDs from a user. The default widget for this input is TextInput.
Syntax
field_name = forms.UUIDField(**options)
Similar Reads
Django Tutorial | Learn Django Framework
Django, built with Python, is designed to help developers build secure, scalable, and feature-rich web applications quickly and efficiently. Whether you're a beginner looking to create your first dynamic website or an experienced developer aiming to enhance your skills, this tutorial will guide you
11 min read
Django view
Views In Django | Python
Django Views are one of the vital participants of the MVT Structure of Django. As per Django Documentation, A view function is a Python function that takes a Web request and returns a Web response. This response can be the HTML contents of a Web page, a redirect, a 404 error, an XML document, an ima
6 min read
Django Function Based Views
Django is a Python-based web framework which allows you to quickly create web application without all of the installation or dependency problems that you normally will find with other frameworks. Django is based on MVT (Model View Template) architecture and revolves around CRUD (Create, Retrieve, Up
7 min read
Django Class Based Views
Class-Based Views (CBVs) allow developers to handle HTTP requests in a structured and reusable way. With CBVs, different HTTP methods (like GET, POST) are handled as separate methods in a class, which helps with code organization and reusability.Advantages of CBVsSeparation of Logic: CBVs separate d
6 min read
Class Based vs Function Based Views - Which One is Better to Use in Django?
Django, a powerful Python web framework, has become one of the most popular choices for web development due to its simplicity, scalability and versatility. One of the key features of Django is its ability to handle views and these views can be implemented using either Class-Based Views (CBVs) or Fun
6 min read
Django Templates
Templates are the third and most important part of Django's MVT Structure. A Django template is basically an HTML file that can also include CSS and JavaScript. The Django framework uses these templates to dynamically generate web pages that users interact with. Since Django primarily handles the ba
7 min read
Django Static File
Static Files such as Images, CSS, or JS files are often loaded via a different app in production websites to avoid loading multiple stuff from the same server. This article revolves around, how you can set up the static app in Django and server Static Files from the same.Create and Activate the Virt
3 min read
Django Model
Django Models
A Django model is the built-in feature that Django uses to create tables, their fields, and various constraints. In short, Django Models is the SQL Database one uses with Django. SQL (Structured Query Language) is complex and involves a lot of different queries for creating, deleting, updating, or a
10 min read
Django model data types and fields list
Django models represent the structure of your database tables, and fields are the core components of those models. Fields define the type of data each database column can hold and how it should behave. This artcle covers all major Django model field types and their usage.Defining Fields in a ModelEa
4 min read
Built-in Field Validations - Django Models
Built-in Field Validations in Django models are the default validations that come predefined to all Django fields. Every field comes in with built-in validations from Django validators. For example, IntegerField comes with built-in validation that it can only store integer values and that too in a p
3 min read
How to use User model in Django?
The Djangoâs built-in authentication system is great. For the most part we can use it out-of-the-box, saving a lot of development and testing effort. It fits most of the use cases and is very safe. But sometimes we need to do some fine adjustment so to fit our Web application. Commonly we want to st
3 min read
Meta Class in Models - Django
Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. Itâs free and open source. D
3 min read
get_object_or_404 method in Django Models
Some functions are hard as well as boring to code each and every time. But Django users don't have to worry about that because Django has some awesome built-in functions to make our work easy and enjoyable. Let's discuss get_object_or_404() here. What is get_object_or_404 in Django?get_object_or_404
2 min read
Django Admin Interface - Python
Prerequisites: Django Introduction and Installation Creating a ProjectThe Django Admin Interface is one of the most powerful features of the Django framework. It provides a ready-to-use interface for managing project data through models, allowing developers and site administrators to perform Create,
3 min read
More topics on Django
Handling Ajax request in Django
AJAX (Asynchronous JavaScript and XML) is a web development technique that allows a web page to communicate with the server without reloading the entire page. In Django, AJAX is commonly used to enhance user experience by sending and receiving data in the background using JavaScript (or libraries li
3 min read
Python | User groups with Custom permissions in Django
Let's consider a trip booking service, how they work with different plans and packages. There is a list of product which subscriber gets on subscribing to different packages, provided by the company. Generally, the idea they follow is the level-wise distribution of different products. Let's see the
4 min read
Django Admin Interface - Python
Prerequisites: Django Introduction and Installation Creating a ProjectThe Django Admin Interface is one of the most powerful features of the Django framework. It provides a ready-to-use interface for managing project data through models, allowing developers and site administrators to perform Create,
3 min read
Python | Extending and customizing django-allauth
Prerequisite: Django-allauth setup and Configuration Let's deal with customizing django-allauth signup forms, and intervening in registration flow to add custom processes and validations. Extending the Signup Form or adding custom fields in Django-allauth: One of the most common queries about allaut
4 min read
Django - Dealing with Unapplied Migration Warnings
Django is a powerful web framework that provides a clean, reusable architecture to build robust applications quickly. It embraces the DRY (Don't Repeat Yourself) principle, allowing developers to write minimal, efficient code.Create and setup a Django project:Prerequisite: Django - Creating projectA
2 min read
Sessions framework using django - Python
Django sessions let us store data for each user across different pages, even if theyâre not logged in. The data is saved on the server and a small cookie (sessionid) is used to keep track of the user.A session stores information about a site visitor for the duration of their visit (and optionally be
3 min read
Django Sign Up and login with confirmation Email | Python
Django provides a built-in authentication system that handles users, login, logout, and registration. In this article, we will implement a user registration and login system with email confirmation using Django and django-crispy-forms for elegant form rendering.Install crispy forms using the termina
7 min read