Reference
Standard HttpResponse objects are static structures. They are provided with a block of pre-rendered content at time of construction, and while that content can be modified, it isn’t in a form that makes it easy to perform modifications.
1305 sections across all versions Narrow to Django 6.0 (current) →
Reference
Standard HttpResponse objects are static structures. They are provided with a block of pre-rendered content at time of construction, and while that content can be modified, it isn’t in a form that makes it easy to perform modifications.
Topic guide Using the Django authentication system
Included in the display of this information is a link to a password change form that allows admins to change or unset user passwords.
Topic guide Introduction to class-based views
A basic function-based view that handles forms may look something like this: A similar class-based view might look like: This is a minimal case, but you can see that you would then have the option of customizing this view by …
Topic guide Composite primary keys
As a composite primary key is a virtual field, a field which doesn’t represent a single database column, this field is excluded from ModelForms.
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
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
You are able to use more than one formset in a view if you like. Formsets borrow much of its behavior from forms.
Topic guide Working with forms
Handling forms is a complex business.
Topic guide Working with forms
We’ve described HTML forms briefly, but an HTML <form> is just one part of the machinery required.
Topic guide Creating forms from models
As with regular forms, it’s possible to specify initial data for forms by specifying an initial parameter when instantiating the form.
Topic guide Creating forms from models
Using the localized_fields parameter, you can enable localization for fields in the form. If localized_fields is set to the special value '__all__', all fields will be localized.
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 …
Topic guide Translation
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.
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.
Topic guide Serializing Django objects
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.
FAQ FAQ: The admin
You’ve got several options. If you want to piggyback on top of an add/change form that Django automatically generates, you can attach arbitrary JavaScript modules to the page via the model’s class Admin js parameter.
How-to How to use Django’s CSRF protection Edge cases
There are cases when CsrfViewMiddleware.process_view may not have run before your view is run - 404 and 500 handlers, for example - but you still need the CSRF token in a form. Solution: use requires_csrf_token()
How-to How to create custom model fields Background theory
All of Django’s fields (and when we say fields in this document, we always mean model fields and not form fields) are subclasses of django.db.models.Field.