Internals
Django’s release process
Since version 1.0, Django’s release numbering works as follows: Versions are numbered in the form A.B or A.B.C. A.B is the feature release version number. Each version will be mostly backwards compatible with the previous release.
Tutorial
We’re continuing the web-poll application and will focus on form processing and cutting down our code. NOTE: If you’re having trouble going through this tutorial, please head over to > the Getting Help section of the FAQ.
Reference
Class-based generic views - flattened index
Editing views
classFormView Attributes (with optional accessor): content_type extra_context form_class [get_form_class()] http_method_names initial [get_initial()] prefix [get_prefix()] response_class [render_to_response()] success_url [get_success_url()] template_engine template_name [get_template_names()] Methods as_view() dispatch() form_invalid() form_valid() get() get_context_data() get_form() get_form_kwargs() http_method_not_allowed() post() put() setup()
Reference
Editing mixins
classdjango.views.generic.edit.FormMixin : A mixin class that provides facilities for creating and displaying forms.
Reference
The Django admin site
ModelAdmin objectsModelAdmin options
Use the following options to override the default templates used by the ModelAdmin views: ModelAdmin.add_form_template : Path to a custom template, used by add_view(). ModelAdmin.change_form_template : Path to a custom template, used by change_view().
Reference
The Django admin site
Overriding admin templates
Not every template in contrib/admin/templates/admin may be overridden per app or per model. The following can: actions.html app_index.html change_form.html change_form_object_tools.html change_list.html change_list_object_tools.html change_list_results.html date_hierarchy.html delete_confirmation.html object_history.html pagination.html popup_response.html prepopulated_fields_js.html search_form.html submit_line.html For those templates that cannot be overridden in this …
Reference
GEOS API
Geometry ObjectsGEOSGeometry
This output may be in the form of a string, buffer, or even another object. GEOSGeometry.ewkt : Returns the “extended” Well-Known Text of the geometry. This representation is specific to PostGIS and is a superset of the OGC WKT standard.
Reference
Quite commonly in web applications, you need to display a one-time notification message (also known as “flash message”) to the user after processing a form or some other types of user input.
Reference
The messages framework
Using messages in views and templates
classviews.SuccessMessageMixin : Adds a success message attribute to FormView based classes Example views.py: The cleaned data from the form is available for string interpolation using the %(field_name)s syntax.
Reference
PostgreSQL specific model fields
Range 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.
Reference
The “sites” framework
Example usage
… 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 …
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 …
Reference
The Forms API
Outputting forms as HTML
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, sender, cc_myself.
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 : Used to display HTML or access attributes for a single field of a Form instance.
Reference
The Forms API
More granular output
BoundField.auto_id : The HTML ID attribute for this BoundField. Returns an empty string if Form.auto_id is False.
Reference
Widgets
Customizing widget instances
… 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 …
Reference
Widgets
Built-in widgetsSelector and checkbox widgets
classSelect : - template_name: 'django/forms/widgets/select.html' - option_template_name: 'django/forms/widgets/select_option.html' - Renders as: <select><option ...>...</select>
Reference
Model field reference
Field types
classBigIntegerField(**options) 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.
Reference
Model field reference
Field types
classDateTimeField(auto_now=False,auto_now_add=False,**options) A date and time, represented in Python by a datetime.datetime instance. 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.
Reference
Model field reference
Field types
classGenericIPAddressField(protocol='both',unpack_ipv4=False,**options) 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.