djangodocs.org

654 sections in Django 4.2 Search all versions →

Troubleshooting

Topic guide Time zones FAQ

… your code is comparing these two things: a datetime provided by Django – for instance, a value read from a form or a model field. Since you enabled time zone support, it’s aware. a datetime generated by your code, which …

Topic guide Security in Django

This ensures that a malicious user cannot “replay” a form POST to your website and have another logged in user unwittingly submit that form. The malicious user would have to know the secret, which is user specific (using a cookie).

Topic guide

Django’s serialization framework provides a mechanism for “translating” Django models into other formats.

Cryptographic signing

Topic guide

Ensuring data stored in hidden form fields has not been tampered with. Generating one-time secret URLs for allowing temporary access to a protected resource, for example a downloadable file that a user has paid for.

Isolating apps

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.

O

Index

… (FieldFile method) - (File method) - (GeoIP2 class method) - (Storage method) - openlayers_url (GeoModelAdmin attribute) - OpenLayersWidget (class in django.contrib.gis.forms.widgets) - OperationalError - optimizemigration - django-admin command - optimizemigration command line option - --check | - OPTIONS - setting …

5.0

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.

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.

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 options

Reference The Django admin site ModelAdmin objects

… decorator on the method, passing the `ordering` argument: ```python from django.contrib import admin from django.db import models from django.utils.html import format_html class Person(models.Model): first_name = models.CharField(max_length=50) color_code = models.CharField(max_length=6) @admin.display(ordering="first_name") def colored_first_name(self): return format_html( '<span style="color: #{};">{}</span>', self.color_code, self.first_name, ) …

ModelAdmin methods

Reference The Django admin site ModelAdmin objects

ModelAdmin.save_related(request,form,formsets,change) : 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.get_form(request,obj=None,**kwargs) : Returns a ModelForm class for use in the admin add and change views, see add_view() and change_view(). ModelAdmin.get_formsets_with_inlines(request,obj=None) : Yields (FormSet, InlineModelAdmin) pairs for use in admin add and change views.