djangodocs.org

694 sections in Django 5.2 Search all versions →

Formsets

Topic guide

classBaseFormSet[source] A formset is a layer of abstraction to work with multiple forms on the same page. It can be best compared to a data grid.

Topic guide Formsets

In the rendered HTML, formsets include a prefix on each field’s name. By default, the prefix is 'form', but it can be customized using the formset’s prefix argument.

Topic guide Formsets

Formsets have the following attributes and methods associated with rendering: BaseFormSet.renderer : Specifies the renderer to use for the formset. Defaults to the renderer specified by the FORM_RENDERER setting.

Topic guide Formsets Using a formset in views and templates

If you manually render fields in the template, you can render can_delete parameter with {{ form.DELETE }}: Similarly, if the formset has the ability to order (can_order=True), it is possible to render it with {{ form.ORDER }}.

Topic guide Formsets Using a formset in views and templates

You are able to use more than one formset in a view if you like. Formsets borrow much of its behavior from forms.

The save() method

Topic guide Creating forms from models ModelForm

Calling save_m2m() is only required if you use save(commit=False). When you use a save() on a form, all data – including many-to-many data – is saved without the need for any additional method calls.

pluralidx

Topic guide Translation Internationalization: in JavaScript codeUsing the JavaScript translation catalog

… function works in a similar way to the pluralize template filter, determining if a given count should use a plural form of a word or not: In the simplest case, if no custom pluralization is needed, this returns false for …

Compiling message files

Topic guide Translation Localization: how to create language files

After you create your message file – and each time you make changes to it – you’ll need to compile it into a more efficient form, for use by gettext. Do this with the django-admin compilemessages utility.

Clickjacking protection

Topic guide Security in Django

Clickjacking is a type of attack where a malicious site wraps another site in a frame. This attack can result in an unsuspecting user being tricked into performing unintended actions on the target site.

DjangoJSONEncoder

Topic guide Serializing Django objects Serialization formatsJSON

A subclass of JSONEncoder, it handles these additional types: datetime A string of the form YYYY-MM-DDTHH:mm:ss.sssZ or YYYY-MM-DDTHH:mm:ss.sss+HH:MM as defined in ECMA-262. date A string of the form YYYY-MM-DD as defined in ECMA-262.

Making requests

Topic guide Testing tools The test client

```python >>> c = Client() >>> c.get("/", SCRIPT_NAME="/app/") ``` If you already have the GET arguments in URL-encoded form, you can use that encoding instead of using the data argument.

H

Index

… django.conf.urls) - has_add_permission() (InlineModelAdmin method) - (ModelAdmin method) - has_change_permission() (InlineModelAdmin method) - (ModelAdmin method) - has_changed() (Field method) - (Form method) - has_curve (OGRGeometry attribute) - has_delete_permission() (InlineModelAdmin method) - (ModelAdmin method) - has_error() (Form method) - has_header() (HttpResponse …

L

Index

… (BoundField attribute) - (Field attribute) - (LabelCommand attribute) - (Options attribute) - label_lower (Options attribute) - label_suffix (Field attribute) - (Form attribute) - label_tag() (BoundField method) - LabelCommand (class in django.core.management) - labels (ModelFormOptions attribute) - Lag (class in django.db.models.functions) …

How-to

… can use csrf_protect() on particular views you want to protect (see below). 2. In any template that uses a POST form, use the csrf_token tag inside the <form> element if the form is for an internal URL, e.g.: This should …