Category: Django
-
Django User Registration with Email Confirmation
Generally, we sign up in any website, it sends the confirmation link to activate the account. Or sometime it asks to email to change the email or reset the password of an account. In this tutorial, we will learn how to send the confirmation mail using the Django when someone registers on our web app.…
-
Create CSV with Django
Django uses Python’s built-in CSV library to create Dynamic CSV (Comma Separated Values) file. We can use this library in our project’s view file. Let’s see an example, here we have a Django project to which we are implementing this feature. A view function getfile() is created. Django CSV Example In this example, we are creating CSV…
-
Django Cookie
A cookie is a small piece of information which is stored in the client browser. It is used to store user’s data in a file permanently (or for the specified time). Cookie has its expiry date and time and removes automatically when gets expire. Django provides built-in methods to set and fetch cookie. The set_cookie() method is…
-
Django Session
A session is a mechanism to store information on the server side during the interaction with the web application. In Django, by default session stores in the database and also allows file-based and cache based sessions. It is implemented via a piece of middleware and can be enabled by using the following code. Put django.contrib.sessions.middleware.SessionMiddleware in MIDDLEWARE…
-
Django Exceptions
An exception is an abnormal event that leads to program failure. To deal with this situation, Django uses its own exception classes and supports all core Python exceptions as well. Django core exceptions classes are defined in django.core.exceptions module. This module contains the following classes. Django Exception Classes Exception Description AppRegistryNotReady It is raised when attempting to…
-
Django Request and Response
The client-server architecture includes two major components request and response. The Django framework uses client-server architecture to implement web applications. When a client requests for a resource, a HttpRequest object is created and correspond view function is called that returns HttpResponse object. To handle request and response, Django provides HttpRequest and HttpResponse classes. Each class…
-
Django Middleware
In Django, middleware is a lightweight plugin that processes during request and response execution. Middleware is used to perform a function in the application. The functions can be a security, session, csrf protection, authentication etc. Django provides various built-in middleware and also allows us to write our own middleware. See, settings.py file of Django project that contains…
-
Django Database Migrations
Migration is a way of applying changes that we have made to a model, into the database schema. Django creates a migration file inside the migration folder for each model to create the table schema, and each table is mapped to the model of which migration is created. Django provides the various commands that are used to…
-
Django Database Connectivity
The settings.py file contains all the project settings along with database connection details. By default, Django works with SQLite, database and allows configuring for other databases as well. Database connectivity requires all the connection details such as database name, user credentials, hostname drive name etc. To connect with MySQL, django.db.backends.mysql driver is used to establishing a connection between application and database.…
-
Django File Upload
File upload to the server using Django is a very easy task. Django provides built-in library and methods that help to upload a file to the server. The forms.FileField() method is used to create a file input and submit the file to the server. While working with files, make sure the HTML form tag contains enctype=”multipart/form-data” property. Let’s see…