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
- admin: Provides the Django administration site, which allows you to manage your site's data through a web interface.
- auth: Provides user authentication and authorization functionality, including user management, permissions, and groups.
- contenttypes: Provides a framework for content types, allowing you to create relationships between different models without hardcoding model classes.
- sessions: Provides session management functionality for maintaining state across HTTP requests.
- messages: Provides a way to display temporary messages (e.g., success messages, error messages) to users.
- staticfiles: Provides utilities for managing static files (e.g., CSS, JavaScript) in Django projects.
- 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
-
An administration site
-
An authentication framework
-
A framework for handling content types
-
A session framework
-
A messaging framework
-
A framework for managing static files
Class-based view vs Function-based view
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:
-
GENERIC BASE
-
GENERIC DETAIL
-
GENERIC LIST
-
GENERIC EDIT
- FormView
- CreateView
- UpdateView
- DeleteView
-
GENERIC DATES
- ArchiveIndexView
- YearArchiveView
- MonthArchiveView
- WeekArchiveView
- DayArchiveView
- TodayArchiveView
- DateDetailView
-
AUTH VIEWS