djangodocs.org

717 sections in Django dev Search all versions →

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 Initialization process

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

ModelAdmin options

Reference The Django admin site ModelAdmin objects

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 objects

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 objects

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 objects

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 objects

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 objects

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 Authentication backends

`user_can_authenticate()`[[source]](https://github.com/django/django/blob/main/django/contrib/auth/backends.py#L96) : 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 Geometry ObjectsGEOSGeometry

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

Methods of BoundField

Reference The Forms API More granular output

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.

Widget

Reference Widgets Base widget classes

classWidget(attrs=None)[source] : This abstract class cannot be rendered, but provides the basic attribute attrs. You may also implement or override the render() method on custom widgets.

MultiWidget

Reference Widgets Base widget classes

classMultiWidget(widgets,attrs=None)[source] : A widget that is composed of multiple widgets. MultiWidget works hand in hand with the MultiValueField.