djangodocs.org

711 sections in Django dev Search all versions →

1.10

Internals Django Deprecation Timeline

The following private APIs will be removed from django.db.models.options.Options (Model._meta): get_field_by_name() get_all_field_names() get_fields_with_model() get_concrete_fields_with_model() get_m2m_with_model() get_all_related_objects() get_all_related_objects_with_model() get_all_related_many_to_many_objects() get_all_related_m2m_objects_with_model() The error_message argument of django.forms.RegexField will be removed. The unordered_list filter will no longer support old style lists.

1.9

Internals Django Deprecation Timeline

The model and form IPAddressField will be removed. A stub field will remain for compatibility with historical migrations. AppCommand.handle_app() will no longer be supported. RequestSite and get_current_site() will no longer be importable from django.contrib.sites.models.

1.7

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.

1.6

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.

Namespacing URL names

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.

Troubleshooting

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.

admin

Reference System check framework

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.

ModelAdmin options

Reference The Django admin site

The default value is - (a dash). For example: ModelAdmin.exclude : This attribute, if given, should be a list of field names to exclude from the form.

ModelAdmin methods

Reference The Django admin site

ModelAdmin.save_related(request,form,formsets,change)[source] : The save_related method is given the HttpRequest, the parent ModelForm instance, the list of inline formsets and a boolean value based on whether the parent is being added or changed.

ModelAdmin methods

Reference The Django admin site

ModelAdmin.lookup_allowed(lookup,value,request) : The objects in the changelist page can be filtered with lookups from the URL’s query string. This is how list_filter works, for example. The lookups are similar to what’s used in QuerySet.filter() (e.g. [email protected]).

ModelAdmin methods

Reference The Django admin site

ModelAdmin.response_delete(request,obj_display,obj_id)[source] : Determines the HttpResponse for the delete_view() stage. ModelAdmin.get_formset_kwargs(request,obj,inline,prefix)[source] : A hook for customizing the keyword arguments passed to the constructor of a formset. For example, to pass request to formset forms:

InlineModelAdmin options

Reference The Django admin site

InlineModelAdmin.max_num : This controls the maximum number of forms to show in the inline. This doesn’t directly correlate to the number of objects, but can if the value is small enough.

AdminSite attributes

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.

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.

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.

Nonce usage

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'.

dumpdata

Reference django-admin and manage.py

--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.

Methods of BoundField

Reference The Forms API

If no widget is specified, then the field’s default widget will be used. BoundField.css_classes(extra_classes=None)[source] : When you use Django’s rendering shortcuts, CSS classes are used to indicate required form fields or fields that contain errors.