djangodocs.org

1305 sections across all versions Narrow to Django 6.0 (current) →

Reference PostgreSQL specific model fields

Django’s model and form field implementations use base classes below, and psycopg provides a register_range() to allow use of custom range types. classRangeField(**options) : Base class for model range fields. classdjango.contrib.postgres.forms.BaseRangeField : Base class for form range fields.

dev

Reference The “sites” framework

… lets readers sign up to get notifications when news happens. It’s pretty basic: A reader signs up on a web form and immediately gets an email saying, “Thanks for your subscription.” It’d be inefficient and redundant to implement this sign …

dev

Reference

… easy-to-use protection against Cross Site Request Forgeries. This type of attack occurs when a malicious website contains a link, a form button or some JavaScript that is intended to perform some action on your website, using the credentials of a …

dev

Notes on field ordering

Reference The Forms API

In the as_p(), as_ul() and as_table() shortcuts, the fields are displayed in the order in which you define them in your form class. For example, in the ContactForm example, the fields are defined in the order subject, message, contact_email, urgent.

dev

More granular output

Reference The Forms API

The as_p(), as_ul(), and as_table() methods are shortcuts – they’re not the only way a form object can be displayed. classBoundField[source] : Used to display HTML or access attributes for a single field of a Form instance.

dev

field_classes

Reference Model forms

ModelFormOptions.field_classes : A dictionary that maps a model field name to a Field class, which overrides the form_class used in the model field’s Field.formfield() method.

dev

localized_fields

Reference Model forms

ModelFormOptions.localized_fields : A tuple or list of model field names to be localized. The value '__all__' can be used to specify that all fields should be localized.

dev

modelform_factory

Reference Model forms

modelform_factory(model,form=ModelForm,fields=None,exclude=None,formfield_callback=None,widgets=None,localized_fields=None,labels=None,help_texts=None,error_messages=None,field_classes=None)[source] : Returns a ModelForm class for the given model. You can optionally pass a form argument to use as a starting point for constructing the ModelForm.

dev

Styling widget instances

Reference Widgets

… you will need to specify additional attributes at the time when the widget object is instantiated and assigned to a form field (and perhaps add some rules to your CSS files). For example, take the following form: This form will …

dev

Reference Middleware

classCsrfViewMiddleware[source] : Adds protection against Cross Site Request Forgeries by adding hidden form fields to POST forms and checking requests for the correct value. See the Cross Site Request Forgery protection documentation.

dev

BigIntegerField

Reference Model field reference

classBigIntegerField(**options)[source] A 64-bit integer, much like an IntegerField except that it is guaranteed to fit numbers from -9223372036854775808 to 9223372036854775807. The default form widget for this field is a NumberInput.

dev

BooleanField

Reference Model field reference

classBooleanField(**options)[source] A true/false field. The default form widget for this field is CheckboxInput, or NullBooleanSelect if null=True. The default value of BooleanField is None when Field.default isn’t defined.

dev

DateTimeField

Reference Model field reference

Takes the same extra arguments as DateField. The default form widget for this field is a single DateTimeInput. The admin uses two separate TextInput widgets with JavaScript shortcuts. WARNING: Always use DateTimeField with a datetime.datetime > instance.

dev

FloatField

Reference Model field reference

The default form widget for this field is a NumberInput when localize is False or TextInput otherwise. NOTE: The FloatField class is sometimes mixed up with the > DecimalField class.

dev

GenericIPAddressField

Reference Model field reference

classGenericIPAddressField(protocol='both',unpack_ipv4=False,**options)[source] An IPv4 or IPv6 address, in string format (e.g. 192.0.2.30 or 2a02:42fe::4). The default form widget for this field is a TextInput.

dev

TextField

Reference Model field reference

The default form widget for this field is a Textarea. If you specify a max_length attribute, it will be reflected in the Textarea widget of the auto-generated form field. However it is not enforced at the model or database level.

dev

TimeField

Reference Model field reference

classTimeField(auto_now=False,auto_now_add=False,**options)[source] A time, represented in Python by a datetime.time instance. Accepts the same auto-population options as DateField. The default form widget for this field is a TimeInput. The admin adds some JavaScript shortcuts.

dev

Arguments

Reference Model field reference

ForeignKey.related_name : The name to use for the relation from the related object back to this one. It’s also the default value for related_query_name (the name to use for the reverse filter name from the target model).

dev

Methods

Reference Request and response objects

HttpRequest.build_absolute_uri(location=None)[source] : Returns the absolute URI form of location. If no location is provided, the location will be set to request.get_full_path().

dev

STATIC_URL

Reference Settings

Default: None URL to use when referring to static files located in STATIC_ROOT. Example: "static/" or "https://static.example.com/" If not None, this will be used as the base path for asset definitions (the Media class) and the staticfiles app.

dev