Topic guide
Testing tools
Provided test case classes
Testing form field rendering and error treatment. Testing HTML responses for the presence/lack of a given fragment. Verifying that a template has/hasn't been used to generate a given response content. Verifying that two URLs are equal.
Topic guide
Testing tools
Test cases features
utils.isolate_apps(*app_labels,attr_name=None,kwarg_name=None) : Registers the models defined within a wrapped context into their own isolated apps registry.
Index
… backends.smtp.EmailBackend (class in django.core.mail) - BadRequest - bands (GDALRaster attribute) - base36_to_int() (in module django.utils.http) - base_field (ArrayField attribute) - (django.contrib.postgres.forms.BaseRangeField attribute) - (RangeField attribute) - (SimpleArrayField attribute) - (SplitArrayField attribute) - base_manager_name (Options attribute) - base_session.AbstractBaseSession (class in django.contrib.sessions) …
Index
… (UniqueConstraint attribute) - open() (FieldFile method) - (File method) - (GeoIP2 class method) - (Storage method) - OpenLayersWidget (class in django.contrib.gis.forms.widgets) - OperationalError - OperationCategory (class in django.db.migrations.operations.base) - optimizemigration - django-admin command - optimizemigration command line option - --check …
How-to
How to use Django’s CSRF protection
Using CSRF protection with AJAX
… the JavaScript Cookie library to replace getCookie: NOTE: The CSRF token is also present in the DOM in a masked form, but only if > explicitly included using csrf_token in a template. The cookie > contains the canonical, unmasked token. …
Internals
Django Deprecation Timeline
The undocumented BaseForm._html_output() method will be removed. The ability to return a str, rather than a SafeString, when rendering an ErrorDict and ErrorList will be removed. See the Django 4.1 release notes for more details on these changes.
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.
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.
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.
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.
Internals
Organization of the Django Project
Steering council
The voter registration form and roll of voters is maintained by the DSF Board.
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.
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.
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.
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
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.
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.
Reference
The Django admin site
ModelAdmin objects
ModelAdmin.has_delete_permission(request,obj=None) : Should return True if deleting obj is permitted, False otherwise.
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.
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.