Django's UpdateView is a built-in class-based view that simplifies updating model data from the frontend. It acts like an admin interface for editing existing records. In this tutorial, we'll create a complete example demonstrating how to implement UpdateView for a Student model. Project Setup First, create a Django project and app. Add the app to your settings and configure URLs ? settings.py INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ... Read More
Many online exam platforms and content management systems use rich text editors for text entries, image uploading, and formatted content creation. Quill is a popular WYSIWYG text editor that provides a Django model field to directly store rich content in the database without extra configuration. In this article, we will see how to implement a rich text editor field in Django using django-quill-editor. Installation and Setup First, create a Django project and app with basic configuration. Install the django-quill-editor package ? pip install django-quill-editor In settings.py, add the required configuration ? ... Read More
Django provides many built-in template filters, but you can also create custom filters to extend functionality. Custom filters allow you to process data in templates using your own logic, such as formatting text or performing calculations. In this article, we will learn how to create and use custom template filters in Django. Project Setup First, create a Django project and app with the following structure ? tutorial/ (project) ├── example/ (app) │ ├── templates/ │ │ └── home.html │ ... Read More
In this article, we will see what is humanizer and how to use it in Django. Humanizer is a built-in Django filter that adds a human touch to your project by converting raw data into more readable formats. It's one of the most useful template filters in Django. Humanizer helps convert numbers from numerical figures to words, add commas between large numbers, or convert numbers to readable formats like million or billion. Let's create a Django project to demonstrate its usage. Project Setup First, create a Django project and an app, then configure the project URLs − ... Read More
A DeleteView is a Django generic view that provides an easy way to delete model instances from your application. It handles the deletion logic and provides confirmation functionality, similar to Django's admin interface. Setting Up the Project First, create a Django project and app. Add your app to settings.py − INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'modelFormsDemo', # Your app name ] ... Read More
If you need to add a location field in your form or database, you can use a CharField but it's not the ideal solution. Django provides a third-party package called 'django-countries' that offers a dedicated country field with built-in validation and country list management. In this article, let's see how to use django-countries to add a Country field in Django. Installation and Setup First, create a Django project and an app. Add the app in INSTALLED_APPS and set up URLs. Install the django-countries module ? pip install django-countries In settings.py, add this ? ... Read More
CAPTCHA is a security feature used to verify that users are human, not bots. Django provides an easy way to implement CAPTCHA using the django-simple-captcha library, which generates image-based challenges for user verification. In this article, we'll learn how to add CAPTCHA functionality to a Django website step by step. Installation First, install the required library − pip install django-simple-captcha Django Configuration Settings Configuration Add the CAPTCHA app to your settings.py − INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', ... Read More
In this article, we will see how to make a URL shortener app in Django. It is a simple app which will convert a long URL into a short one using the pyshorteners library. First, create a Django project and an app. Do some basic settings like including URLs of app and adding the app to INSTALLED_APPS in settings.py. Installing Required Package Install the pyshorteners module − pip install pyshorteners Setting Up URLs In app's urls.py − from django.urls import path from .views import url_shortener urlpatterns = [ ... Read More
In this article, we are going to see how to make a super simple counter app using Django sessions. By clicking a button, the counter increments and persists even after closing the browser tab. This demonstrates how to use request.session for state management in Django. Setting Up URLs In urls.py, add the following lines − from django.urls import path from . import views urlpatterns = [ path('', views.counterView, name='counter'), ] Here we set up the counter view on the home URL. Creating the View In views.py, add ... Read More
Pickle in Python is primarily used in serializing and deserializing a Python object structure. In other words, it's the process of converting a Python object into a byte stream to store it in a file/database, maintain program state across sessions, or transport data over the network. In this article, we are going to see how to make a Django field which will save pickle objects. We will work with models.py and Django shell to demonstrate the functionality. Installation First, install the django-picklefield package − pip install django-picklefield Creating the Model In models.py ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Economics & Finance