DEV Community

Pranav Bakare
Pranav Bakare

Posted on

Django | Terminologies | PART 2

Here are some key terminologies in Django, along with detailed explanations:

  1. Model

In Django, a Model is a class that defines the structure of your database. It acts as the blueprint for creating, reading, updating, and deleting data. Each model corresponds to a database table, and each attribute of the model represents a field in that table. Models use Django’s Object-Relational Mapping (ORM) to interact with the database, enabling you to write database queries using Python code.

  1. View

A View in Django is a function or class that takes a web request and returns a web response. It contains the logic needed to process user requests, interact with models, and render templates. Views act as the controller in the MVC (Model-View-Controller) architecture, even though Django refers to its pattern as MTV (Model-Template-View).

  1. Template

Templates are HTML files with placeholders for dynamic data. They define how the content will be displayed to the user. Django uses its templating language to render data dynamically into HTML, allowing for the reuse of code and consistent presentation across pages. Templates separate the presentation layer from business logic.

  1. URL Dispatcher (URLconf)

The URL Dispatcher is a configuration that maps URLs to views. Also known as urls.py, it routes incoming requests to the appropriate view based on the URL pattern. This allows you to define clean, readable URLs for your web application, making it easier for users to navigate your site.

  1. ORM (Object-Relational Mapping)

ORM is a technique used by Django to interact with the database using Python code instead of raw SQL queries. It allows developers to manipulate the database by creating Python objects (models) and provides methods to perform CRUD (Create, Read, Update, Delete) operations, query optimization, and relationships between tables.

  1. Django Admin

The Django Admin is a built-in tool that provides a web-based interface for managing database content. It allows administrators to add, modify, and delete records in the database without writing any code. The admin interface is highly customizable and helps in rapid application development and testing.

  1. Middleware

Middleware is a layer between the request and response cycle. It processes the request before it reaches the view and processes the response before it is sent to the client. Middleware can perform tasks like authentication, session management, and modifying request/response headers. It helps in adding cross-cutting functionality.

  1. Django Forms

Forms in Django are used to handle user input data. They can be used to create HTML forms, validate form data, and process form submissions. Django forms come with built-in validation and security measures, reducing the need for manual input handling and ensuring that data is clean before it is saved to the database.

  1. QuerySet

A QuerySet is a collection of database queries to retrieve, filter, or manipulate data from a model. It represents a group of records that match certain criteria and allows for chaining operations. QuerySets are lazy, meaning they don't hit the database until they are explicitly evaluated, which optimizes performance.

  1. Static Files

Static Files refer to assets such as images, CSS files, JavaScript, and other files that don’t change during the app’s execution. Django provides mechanisms to serve static files during development and helps in collecting them for deployment.

  1. Migration

Migrations are files that Django uses to propagate changes you make to your models into your database schema. Instead of writing raw SQL, Django automatically creates migrations for you, which ensures that database tables and columns are created, altered, or deleted according to your model definitions.

  1. Django REST Framework (DRF)

DRF is an extension to Django that helps in building RESTful APIs. It simplifies the process of creating web APIs and provides tools for serialization, authentication, permissions, and viewsets. It follows the principles of REST (Representational State Transfer), making it easier to build web services that can interact with front-end applications or third-party clients.

  1. Serializers

Serializers in DRF convert complex data types like QuerySets and model instances into native Python data types that can then be easily rendered into JSON, XML, or other content types. They also handle deserialization, allowing parsed data to be converted back into complex types after validating the incoming data.

  1. CSRF (Cross-Site Request Forgery) Protection

Django has built-in CSRF Protection, which ensures that malicious users cannot trick authenticated users into submitting unwanted actions on a website. It uses a CSRF token to verify that each POST request is coming from a trusted source.

  1. Signals

Signals allow decoupled applications to get notified when certain actions occur elsewhere in the application. For example, you can use signals to automatically create a profile for a user when they register. They help maintain the separation of concerns and reduce the tight coupling between components.

  1. Context Processors

Context Processors are functions that inject certain data into the context of every template. This allows you to make variables available globally across your templates without passing them explicitly in every view. It is useful for adding data that needs to be accessible on all pages, such as user information or site settings.

These terminologies and components work together to make Django a robust framework for building scalable web applications.

Top comments (0)