Skip to content

Intro

django.contrib is a package in Django that contains a collection of optional, reusable components contributed by the Django community. These components are maintained by the Django core team but are not essential to the core functionality of Django. Instead, they provide additional features that can be integrated into Django projects as needed.

Some of the most commonly used packages within django.contrib include:

Note

  1. admin: Provides the Django administration site, which allows you to manage your site's data through a web interface.
  2. auth: Provides user authentication and authorization functionality, including user management, permissions, and groups.
  3. contenttypes: Provides a framework for content types, allowing you to create relationships between different models without hardcoding model classes.
  4. sessions: Provides session management functionality for maintaining state across HTTP requests.
  5. messages: Provides a way to display temporary messages (e.g., success messages, error messages) to users.
  6. staticfiles: Provides utilities for managing static files (e.g., CSS, JavaScript) in Django projects.
  7. gis: Provides geographic information system (GIS) functionality for working with spatial data.

These packages can be included in your Django project by adding them to the INSTALLED_APPS setting in your project's settings.py file. For example:

INSTALLED_APPS = [
    ...
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    ...
]

By including these packages, you can leverage their functionality in your Django project without having to build everything from scratch.


packages


Class-based view vs Function-based view

FBV vs CBV

Those are the main differences between function-based views and class-based views. Now, Django’s generic class-based views are a different story.

Generic Class-Based Views

The generic class-based-views was introduced to address the common use cases in a Web application, such as creating new objects, form handling, list views, pagination, archive views and so on.

  • They come in the Django core, and you can implement them from the module django.views.generic.
  • They are great and can speed up the development process.

Here is an overview of the available views:



Reference