Internals
Django Deprecation Timeline
The undocumented check_for_test_cookie method in AuthenticationForm will be removed following an accelerated deprecation. Users subclassing this form should remove calls to this method, and instead ensure that their auth related views are CSRF protected, which ensures that cookies are enabled.
dev
Internals
Django Deprecation Timeline
They will be removed. The form wizard has been refactored to use class-based views with pluggable backends in 1.4. The previous implementation will be removed. Legacy ways of calling cache_page() will be removed.
dev
Internals
Organization of the Django Project
The voter registration form and roll of voters is maintained by the DSF Board.
dev
Tutorial
Advanced tutorial: How to write reusable apps
A package can be imported with import foo.bar or from foo import > bar. For a directory (like polls) to form a package, it must contain > a special file __init__.py, even if this file is empty.
dev
Tutorial
Writing your first Django app, part 3
… application namespace: polls/urls.py Now change your polls/index.html template from: polls/templates/polls/index.html to point at the namespaced detail view: polls/templates/polls/index.html When you’re comfortable with writing views, read part 4 of this tutorial to learn the basics about form processing and generic views.
dev
Reference
Applications
This concept is known as “lazy evaluation”. django.contrib.admin automatically performs autodiscovery of admin modules in installed applications. To prevent it, change your INSTALLED_APPS to contain 'django.contrib.admin.apps.SimpleAdminConfig' instead of 'django.contrib.admin'. RuntimeWarning: Accessing the database during app initialization is discouraged.
dev
Reference
System check framework
contrib app checks
Admin checks are all performed as part of the admin tag. The following checks are performed on any ModelAdmin (or subclass) that is registered with the admin site: admin.E001: The value of raw_id_fields must be a list or tuple.
Reference
The Django admin site
AdminSite.login_form : Subclass of AuthenticationForm that will be used by the admin site login view. AdminSite.logout_template : Path to a custom template that will be used by the admin site logout view.
dev
Reference
django.contrib.auth
`user_can_authenticate()`[[source]](https://github.com/django/django/blob/main/django/contrib/auth/backends.py#L98) : Returns whether the user is allowed to authenticate. To match the behavior of [`AuthenticationForm.confirm_login_allowed()`](../../topics/auth/default.md#django.contrib.auth.forms.AuthenticationForm.confirm_login_allowed), this method returns `False` for users with [`is_active=False`](#django.contrib.auth.models.User.is_active). Custom user models that don’t have an [`is_active`](../../topics/auth/customizing.md#django.contrib.auth.models.CustomUser.is_active) field are allowed.
dev
Reference
GEOS API
PreparedGeometry objects are optimized for the contains, intersects, covers, crosses, disjoint, overlaps, touches and within operations. Refer to the Prepared Geometries documentation for more information. GEOSGeometry.srs : Returns a SpatialReference object corresponding to the SRID of the geometry or None.
dev
Reference
Content Security Policy
A CSP nonce (“number used once”) is a unique, random value generated per HTTP response. Django supports nonces as a secure way to allow specific inline <script> or <style> elements to execute without relying on 'unsafe-inline'.
dev
Reference
django-admin and manage.py
Available commands
--format FORMAT Specifies the serialization format of the output. Defaults to JSON. Supported formats are listed in Serialization formats. --indent INDENT Specifies the number of indentation spaces to use in the output.
Reference
Widgets
classMultiWidget(widgets,attrs=None)[source] : A widget that is composed of multiple widgets. MultiWidget works hand in hand with the MultiValueField.
dev
Reference
Model field reference
If you want to be able to modify this field, set the following instead of auto_now_add=True: The default form widget for this field is a DateInput. The admin adds a JavaScript calendar, and a shortcut for “Today”.
dev
Reference
Model field reference
classField[source] : Field is an abstract class that represents a database table column. Django uses fields to create the database table (db_type()), to map Python types to database (get_prep_value()) and vice-versa (from_db_value()).
dev
Reference
QuerySet API reference
where / tables You can define explicit SQL WHERE clauses — perhaps to perform non-explicit joins — by using where. You can manually add tables to the SQL FROM clause by using tables.
dev
Topic guide
Using the Django authentication system
If your AUTH_USER_MODEL inherits from AbstractBaseUser or implements its own get_session_auth_hash() method, authenticated sessions will include the hash returned by this function. In the AbstractBaseUser case, this is an HMAC of the password field.
dev
Topic guide
Introduction to class-based views
… Django uses to build class-based generic views are built for maximum flexibility, and as such have many hooks in the form of default method implementations and attributes that you are unlikely to be concerned with in the simplest use cases. …
dev
Topic guide
Introduction to class-based views
… is worth noting that what your method returns is identical to what you return from a function-based view, namely some form of HttpResponse. This means that http shortcuts or TemplateResponse objects are valid to use inside a class-based view. While …
dev
Topic guide
Using mixins with class-based views
The _detail part can be changed by setting template_name_suffix on a subclass to something else. (For instance, the generic edit views use _form for create and update views, and _confirm_delete for delete views.)
dev