Wsgirequest Object Does Not Support Item Assignment Abroad

Django 1.8 has been designated as Django’s second long-term support release. It will receive security updates for at least three years after its release. Support for the previous LTS, Django 1.4, will end 6 months from the release date of Django 1.8.

Python compatibility¶

Django 1.8 requires Python 2.7, 3.2, 3.3, 3.4, or 3.5. We highly recommend and only officially support the latest release of each series.

Django 1.8 is the first release to support Python 3.5.

Due to the end of upstream support for Python 3.2 in February 2016, we won’t test Django 1.8.x on Python 3.2 after the end of 2016.

What’s new in Django 1.8¶

Multiple template engines¶

Django 1.8 defines a stable API for integrating template backends. It includes built-in support for the Django template language and for . It supports rendering templates with multiple engines within the same project. Learn more about the new features in the topic guide and check the upgrade instructions in older versions of the documentation.

New PostgreSQL specific functionality¶

Django now has a module with extensions for PostgreSQL specific features, such as , , Range Fields, and lookup. A full breakdown of the features is available in the documentation.

New data types¶

  • Django now has a for storing universally unique identifiers. It is stored as the native data type on PostgreSQL and as a fixed length character field on other backends. There is a corresponding .
  • Django now has a for storing periods of time - modeled in Python by . It is stored in the native data type on PostgreSQL, as a on Oracle, and as a of microseconds on other backends. Date and time related arithmetic has also been improved on all backends. There is a corresponding .

Query Expressions, Conditional Expressions, and Database Functions¶

Query Expressions allow you to create, customize, and compose complex SQL expressions. This has enabled annotate to accept expressions other than aggregates. Aggregates are now able to reference multiple fields, as well as perform arithmetic, similar to objects. has also gained the ability to accept expressions.

Conditional Expressions allow you to use … … logic within queries.

A collection of database functions is also included with functionality such as , , and .

data setup¶

has been refactored to allow for data initialization at the class level using transactions and savepoints. Database backends which do not support transactions, like MySQL with the MyISAM storage engine, will still be able to run these tests but won’t benefit from the improvements. Tests are now run within two nested blocks: one for the whole class and one for each test.

  • The class method adds the ability to setup test data at the class level. Using this technique can speed up the tests as compared to using .
  • Fixture loading within is now performed once for the whole .

Minor features¶

  • now has a method to allow limiting access to the module on the admin index page.
  • now has an attribute that supports showing a link to an inline object’s change form.
  • Use the new in to limit the choices to foreign objects which are attached to those from the .
  • The displays a summary of objects to be deleted on the deletion confirmation page.
  • The jQuery library embedded in the admin has been upgraded to version 1.11.2.
  • You can now specify in order to display a link to the front-end site.
  • You can now specify to control whether or not the full count of objects should be displayed on a filtered admin page.
  • The method now has an parameter.
  • You can now control who may login to the admin site by overriding only and . The template has a new block which contains the user-specific header. A new context variable , which gets its value from , indicates whether the user may access the site.
  • Foreign key dropdowns now have buttons for changing or deleting related objects using a popup.

  • A new GeoJSON serializer is now available.
  • It is now allowed to include a subquery as a geographic lookup argument, for example .
  • The SpatiaLite backend now supports and aggregates when the database version is 3.0 or later.
  • The PostGIS 2 and the SpatiaLite initialization commands are now automatically run by .
  • The GDAL interface now supports retrieving properties of raster (image) data file.
  • Compatibility shims for and changed in Django 1.2 have been removed.
  • All GDAL-related exceptions are now raised with . The former has been kept for backwards compatibility but should not be used any longer.

Cache¶

  • The method of the backend is now thread-safe.

Database backends¶

  • The MySQL backend no longer strips microseconds from values as MySQL 5.6.4 and up supports fractional seconds depending on the declaration of the datetime field (when includes fractional precision greater than 0). New datetime database columns created with Django 1.8 and MySQL 5.6.4 and up will support microseconds. See the MySQL database notes for more details.
  • The MySQL backend no longer creates explicit indexes for foreign keys when using the InnoDB storage engine, as MySQL already creates them automatically.
  • The Oracle backend no longer defines the feature as . Instead, Oracle will now include a cache busting clause when getting the description of a table.

File Storage¶

  • and now take a argument to implement storage-level maximum filename length constraints. Filenames exceeding this argument will get truncated. This prevents a database error when appending a unique suffix to a long filename that already exists on the storage. See the deprecation note about adding this argument to your custom storage classes.

Forms¶

  • Form widgets now render attributes with a value of or as HTML5 boolean attributes.
  • The new method allows checking if a specific error has happened.
  • If is defined on a form, then the tags for required fields will have this class present in its attributes.
  • The rendering of non-field errors in unordered lists () now includes in its list of classes to distinguish them from field-specific errors.
  • now accepts a argument, which will override the form’s . This enables customizing the suffix on a per-field basis — previously it wasn’t possible to override a form’s while using shortcuts such as in templates.
  • now accepts an argument, which will override the top list choice label when is not required.
  • After an has been cleaned and validated, the object will have an additional attribute containing the Pillow instance used to check if the file was a valid image. It will also update with the image’s content type as determined by Pillow.
  • You can now pass a callable that returns an iterable of choices when instantiating a .

Internationalization¶

  • can now be a list of strings representing module paths. This allows importing several format modules from different reusable apps. It also allows overriding those custom formats in your main Django project.

Management Commands¶

  • Database connections are now always closed after a management command called from the command line has finished doing its job.
  • Commands from alternate package formats like eggs are now also discovered.
  • The new option allows specifying a file to which the serialized data is written.
  • The new and options allow excluding specific locales from processing.
  • now has a or option which includes fuzzy translations into compiled files.
  • The option now ignores data for models that no longer exist.
  • now uses daemon threads for faster reloading.
  • now outputs . It is also able to introspect for MySQL and PostgreSQL databases.
  • When calling management commands with options using , the option name can match the command line option name (without the initial dashes) or the final option destination variable name, but in either case, the resulting option received by the command is now always the name specified in the command option definition (as long as the command uses the module).
  • The command now supports MySQL’s optional SSL certificate authority setting ().
  • The new allows giving the migration(s) a custom name instead of a generated one.
  • The command now prevents repeated fixture loading. If contains duplicates or a default fixture directory path (), an exception is raised.
  • The new option allows exiting with an error code if no migrations are created.
  • The new command allows listing all migrations and their dependencies in a project.

Models¶

  • Django now logs at most 9000 queries in , in order to prevent excessive memory usage in long-running processes in debug mode.
  • There is now a model option to define a for all relational fields of a model.
  • Pickling models and querysets across different versions of Django isn’t officially supported (it may work, but there’s no guarantee). An extra variable that specifies the current Django version is now added to the pickled state of models and querysets, and Django raises a when these objects are unpickled in a different version than the one in which they were pickled.
  • Added which Django uses whenever objects are loaded using the ORM. The method allows customizing model loading behavior.
  • now allows you to escape a literal sequence using .
  • Custom Lookups can now be registered using a decorator pattern.
  • The new attribute allows creating bilateral transformations. These transformations are applied to both and when used in a lookup expression, providing opportunities for more sophisticated lookups.
  • SQL special characters (, %, _) are now escaped properly when a pattern lookup (e.g. , , etc.) is used with an expression as the right-hand side. In those cases, the escaping is performed by the database, which can lead to somewhat complex queries involving nested function calls.
  • You can now refresh model instances by using .
  • You can now get the set of deferred fields for a model using .
  • Model field ’s are now used when primary key field’s are set to .

Signals¶

  • Exceptions from the tuples returned by now have their traceback attached as a attribute.
  • The argument, which contains the WSGI environment structure from the request, was added to the signal.
  • You can now import the signal from to avoid loading in non-test situations. Django no longer does so itself.

Templates¶

  • now supports domain-only links that include characters after the top-level domain (e.g. and ).
  • doesn’t treat exclamation marks at the end of a domain or its query string as part of the URL (the URL in e.g. is )
  • Added a class that loads Django templates from a Python dictionary.
  • The tag can now store its output in a context variable with the usual syntax: .

Requests and Responses¶

  • now respects paths starting with .
  • The method now handles paths starting with correctly.
  • If is and a request raises a , the response will be rendered with a detailed error page.
  • The argument of is now optional, defaulting to , so a blank can now be instantiated with instead of or .
  • The and attributes of an object are now s rather than dictionaries, and the attribute is now a . This brings this class into line with the documentation and with .
  • The attribute was added.
  • now follows RFC in converting URI to IRI, using .
  • The method now escapes unsafe characters from the path portion of a Uniform Resource Identifier (URI) properly.
  • now implements a few additional methods like so that instances can be used as stream objects.
  • The new method allows setting a header unless it has already been set.
  • You can use the new to stream files.
  • The decorator for conditional view processing now supports the header.

Tests¶

  • The and methods were implemented, allowing you to create requests in your tests.
  • The argument was added to . This allows you to assert that a template was rendered a specific number of times.
  • The new assertion allows you to test that two JSON fragments are not equal.
  • Added options to the command to preserve the test database (), to run the test cases in reverse order (), and to enable SQL logging for failing tests ().
  • Added the attribute to test client responses.
  • Added several settings that allow customization of test tablespace parameters for Oracle: , , and .
  • The decorator can now affect the master router in .
  • Added test client support for file uploads with file-like objects.
  • A shared cache is now used when testing with an SQLite in-memory database when using Python 3.4+ and SQLite 3.7.13+. This allows sharing the database between threads.

Validators¶

  • now supports IPv6 addresses, unicode domains, and URLs containing authentication data.

Backwards incompatible changes in 1.8¶

Warning

In addition to the changes outlined in this section, be sure to review the deprecation plan for any features that have been removed. If you haven’t updated your code within the deprecation timeline for a given feature, its removal may appear as a backwards incompatible change.

Assigning unsaved objects to relations raises an error¶

Note

To more easily allow in-memory usage of models, this change was reverted in Django 1.8.4 and replaced with a check during . For example:

A similar check on assignment to reverse one-to-one relations was removed in Django 1.8.5.

>>> book=Book.objects.create(name="Django")>>> book.author=Author(name="John")>>> book.save()Traceback (most recent call last):...ValueError: save() prohibited to prevent data loss due to unsaved related object 'author'.

Assigning unsaved objects to a , , and now raises a .

Previously, the assignment of an unsaved object would be silently ignored. For example:

Now, an error will be raised to prevent data loss:

If you require allowing the assignment of unsaved instances (the old behavior) and aren’t concerned about the data loss possibility (e.g. you never save the objects to the database), you can disable this check by using the attribute. (This attribute was removed in 1.8.4 as it’s no longer relevant.)

>>> book=Book.objects.create(name="Django")>>> book.author=Author(name="John")>>> book.author.save()>>> book.save()>>> Book.objects.get(name="Django")>>> book.author>>>
>>> book.author=Author(name="john")Traceback (most recent call last):...ValueError: Cannot assign "<Author: John>": "Author" instance isn't saved in the database.

Management commands that only accept positional arguments¶

If you have written a custom management command that only accepts positional arguments and you didn’t specify the command variable, you might get an error like , as variable parsing is now based on which doesn’t implicitly accept positional arguments. You can make your command backwards compatible by simply setting the class variable. However, if you don’t have to keep compatibility with older Django versions, it’s better to implement the new method as described in Writing custom django-admin commands.

Custom test management command arguments through test runner¶

The method to add custom arguments to the test management command through the test runner has changed. Previously, you could provide an option_list class variable on the test runner to add more arguments (à la ). Now to implement the same behavior, you have to create an class method on the test runner and call to add any custom arguments, as parser is now an instance.

Model check ensures auto-generated column names are within limits specified by database¶

A field name that’s longer than the column name length supported by a database can create problems. For example, with MySQL you’ll get an exception trying to create the column, and with PostgreSQL the column name is truncated by the database (you may see a warning in the PostgreSQL logs).

A model check has been introduced to better alert users to this scenario before the actual creation of database tables.

If you have an existing model where this check seems to be a false positive, for example on PostgreSQL where the name was already being truncated, simply use to specify the name that’s being used.

The check also applies to the columns generated in an implicit model. If you run into an issue there, use to create an explicit model and then specify on its column(s) as needed.

Query relation lookups now check object types¶

Querying for model lookups now checks if the object passed is of correct type and raises a if not. Previously, Django didn’t care if the object was of correct type; it just used the object’s related field attribute (e.g. ) for the lookup. Now, an error is raised to prevent incorrect lookups:

>>> book=Book.objects.create(name="Django")>>> book=Book.objects.filter(author=book)Traceback (most recent call last):...ValueError: Cannot query "<Book: Django>": Must be "Author" instance.

Default increased to 254¶

The old default 75 character was not capable of storing all possible RFC3696/5321-compliant email addresses. In order to store all possible valid email addresses, the has been increased to 254 characters. You will need to generate and apply database migrations for your affected models (or add if you wish to keep the length on your current fields). A migration for is included.

Support for PostgreSQL versions older than 9.0¶

The end of upstream support periods was reached in July 2014 for PostgreSQL 8.4. As a consequence, Django 1.8 sets 9.0 as the minimum PostgreSQL version it officially supports.

This also includes dropping support for PostGIS 1.3 and 1.4 as these versions are not supported on versions of PostgreSQL later than 8.4.

Django also now requires the use of Psycopg2 version 2.4.5 or higher (or 2.5+ if you want to use ).

Support for MySQL versions older than 5.5¶

The end of upstream support periods was reached in January 2012 for MySQL 5.0 and December 2013 for MySQL 5.1. As a consequence, Django 1.8 sets 5.5 as the minimum MySQL version it officially supports.

Support for Oracle versions older than 11.1¶

The end of upstream support periods was reached in July 2010 for Oracle 9.2, January 2012 for Oracle 10.1, and July 2013 for Oracle 10.2. As a consequence, Django 1.8 sets 11.1 as the minimum Oracle version it officially supports.

Python compatibility¶

Django 1.9 requires Python 2.7, 3.4, or 3.5. We highly recommend and only officially support the latest release of each series.

The Django 1.8 series is the last to support Python 3.2 and 3.3.

What’s new in Django 1.9¶

Performing actions after a transaction commit¶

The new hook allows performing actions after a database transaction is successfully committed. This is useful for tasks such as sending notification emails, creating queued tasks, or invalidating caches.

This functionality from the django-transaction-hooks package has been integrated into Django.

Password validation¶

Django now offers password validation to help prevent the usage of weak passwords by users. The validation is integrated in the included password change and reset forms and is simple to integrate in any other code. Validation is performed by one or more validators, configured in the new setting.

Four validators are included in Django, which can enforce a minimum length, compare the password to the user’s attributes like their name, ensure passwords aren’t entirely numeric, or check against an included list of common passwords. You can combine multiple validators, and some validators have custom configuration options. For example, you can choose to provide a custom list of common passwords. Each validator provides a help text to explain its requirements to the user.

By default, no validation is performed and all passwords are accepted, so if you don’t set , you will not see any change. In new projects created with the default template, a simple set of validators is enabled. To enable basic validation in the included auth forms for your project, you could set, for example:

See Password validation for more details.

AUTH_PASSWORD_VALIDATORS=[{'NAME':'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',},{'NAME':'django.contrib.auth.password_validation.MinimumLengthValidator',},{'NAME':'django.contrib.auth.password_validation.CommonPasswordValidator',},{'NAME':'django.contrib.auth.password_validation.NumericPasswordValidator',},]

Permission mixins for class-based views¶

Django now ships with the mixins , , , and to provide the functionality of the for class-based views. These mixins have been taken from, or are at least inspired by, the django-braces project.

There are a few differences between Django’s and ’ implementation, though:

  • The attribute can only be or . Custom exceptions or callables are not supported.
  • The method does not take a argument. The current request is available in .
  • The custom of does not take a argument. The current user is available in .
  • The attribute supports a string (defining one permission) or a list/tuple of strings (defining multiple permissions) that need to be fulfilled to grant access.
  • The new attribute allows passing a message to the exception.

New styling for ¶

The admin sports a modern, flat design with new SVG icons which look perfect on HiDPI screens. It still provides a fully-functional experience to YUI’s A-grade browsers. Older browser may experience varying levels of graceful degradation.

Running tests in parallel¶

The command now supports a option to run a project’s tests in multiple processes in parallel.

Each process gets its own database. You must ensure that different test cases don’t access the same resources. For instance, test cases that touch the filesystem should create a temporary directory for their own use.

This option is enabled by default for Django’s own test suite provided:

  • the OS supports it (all but Windows)
  • the database backend supports it (all the built-in backends but Oracle)

Minor features¶

  • Admin views now have or attributes.
  • The URL of the admin change view has been changed (was at by default and is now at ). This should not affect your application unless you have hardcoded admin URLs. In that case, replace those links by reversing admin URLs instead. Note that the old URL still redirects to the new one for backwards compatibility, but it may be removed in a future version.
  • was added to allow changing the values used in the admin’s changelist query based on the request.
  • The context variable, which lists the available applications for the current user, has been added to the method.
  • and were added to override the display of empty values in admin change list. You can also customize the value for each field.
  • Added jQuery events when an inline form is added or removed on the change form page.
  • The time picker widget includes a ‘6 p.m’ option for consistency of having predefined options every 6 hours.
  • JavaScript slug generation now supports Romanian characters.

  • The model section of the now also describes methods that take arguments, rather than ignoring them.

  • The default iteration count for the PBKDF2 password hasher has been increased by 20%. This backwards compatible change will not affect users who have subclassed to change the default value.
  • The will now update passwords if its attribute is changed.
  • and were moved to a new module so that they can be imported without including in (doing so raised a deprecation warning in older versions and is no longer supported in Django 1.9).
  • The permission argument of accepts all kinds of iterables, not only list and tuples.
  • The new makes it possible to use for setups where the header is only populated on login pages instead of every request in the session.
  • The view accepts an parameter.

  • All methods have been deprecated and replaced by equivalent database functions. As soon as the legacy methods have been replaced in your code, you should even be able to remove the special from your GIS-enabled classes.
  • The GDAL interface now supports instantiating file-based and in-memory GDALRaster objects from raw data. Setters for raster properties such as projection or pixel values have been added.
  • For PostGIS users, the new allows storing GDALRaster objects. It supports automatic spatial index creation and reprojection when saving a model. It does not yet support spatial querying.
  • The new method allows warping a raster by specifying target raster properties such as origin, width, height, or pixel size (amongst others).
  • The new method allows transforming a raster into a different spatial reference system by specifying a target .
  • The new class allows using MaxMind’s GeoLite2 databases which includes support for IPv6 addresses.
  • The default OpenLayers library version included in widgets has been updated from 2.13 to 2.13.1.

  • now handles the case where returns , e.g. . If the lookup fails because the host does not match a record in the database and the host has a port, the port is stripped and the lookup is retried with the domain part only.

  • Support for multiple enclosures per feed item has been added. If multiple enclosures are defined on a RSS feed, an exception is raised as RSS feeds, unlike Atom feeds, do not support multiple enclosures per feed item.

Cache¶

  • now has a method.
  • now sends more persuasive headers (added to ) to better prevent caching. This was also added in Django 1.8.8.

Database backends¶

  • The PostgreSQL backend () is also available as . The old name will continue to be available for backwards compatibility.

Forms¶

  • accepts the new option to customize the type of the fields. See Overriding the default fields for details.
  • You can now specify the order in which form fields are rendered with the attribute, the constructor argument , or the method.
  • A form prefix can be specified inside a form class, not only when instantiating a form. See Prefixes for forms for details.
  • You can now specify keyword arguments that you want to pass to the constructor of forms in a formset.
  • now accepts an argument to allow Unicode characters in slugs.
  • now accepts a argument to strip input data of leading and trailing whitespace. As this defaults to this is different behavior from previous releases.
  • Form fields now support the argument, allowing the field widget to be displayed disabled by browsers.
  • It’s now possible to customize bound fields by overriding a field’s method.

Internationalization¶

  • The view now properly redirects to translated URLs, when available.
  • The view now works correctly if used multiple times with different configurations on the same page.
  • The function gained an argument to help resolve ambiguous times during DST transitions.
  • You can now use locale variants supported by gettext. These are usually used for languages which can be written in different scripts, for example Latin and Cyrillic (e.g. ).
  • Added the view to help build a custom client-side i18n library upon Django translations. It returns a JSON object containing a translations catalog, formatting settings, and a plural rule.
  • Added the attribute to the object returned by the template tag. Also added a corresponding template filter: .
  • You can now run from the root directory of your project and it will find all the app message files that were created by .
  • now calls xgettext once per locale directory rather than once per translatable file. This speeds up localization builds.
  • supports assigning its output to a variable using .
  • Two new languages are available: Colombian Spanish and Scottish Gaelic.

Management Commands¶

  • The new command lets you send a test email to easily confirm that email sending through Django is working.
  • To increase the readability of the SQL code generated by , the SQL code generated for each migration operation is preceded by the operation’s description.
  • The command output is now deterministically ordered. Moreover, when the option is specified, it also shows a progress bar in the terminal.
  • The command now has a flag to print out the SQL rather than execute it.
  • The command creates an file. Since it doesn’t use (a discouraged API), you must specify the app config’s path, e.g. , in for it to be used (instead of just ).
  • When using the PostgreSQL backend, the command can connect to the database using the password from your settings file (instead of requiring it to be manually entered).
  • The package may be run as a script, i.e. , which will behave the same as .
  • Management commands that have the option now also take as an alias for that option.

Migrations¶

  • Initial migrations are now marked with an class attribute which allows to more easily detect initial migrations.

  • Added support for serialization of and instances.

  • When supplying as a value in , Django will consider the app an app without migrations.

  • When applying migrations, the “Rendering model states” step that’s displayed when running migrate with verbosity 2 or higher now computes only the states for the migrations that have already been applied. The model states for migrations being applied are generated on demand, drastically reducing the amount of required memory.

    However, this improvement is not available when unapplying migrations and therefore still requires the precomputation and storage of the intermediate migration states.

    This improvement also requires that Django no longer supports mixed migration plans. Mixed plans consist of a list of migrations where some are being applied and others are being unapplied. This was never officially supported and never had a public API that supports this behavior.

  • The command now supports specifying the starting migration from which migrations will be squashed.

Models¶

  • now works on proxy models.
  • Database configuration gained a option for interacting with databases that store datetimes in local time and don’t support time zones when is .
  • Added the method to the related managers created by , , and .
  • The method on a reverse foreign key now has a parameter to allow executing one query regardless of the number of objects being added rather than one query per object.
  • Added the parameter to to allow deleting only a child’s data in a model that uses multi-table inheritance.
  • and return the number of objects deleted.
  • Added a system check to prevent defining both and on the same model.
  • lookups can be chained with other lookups (such as , , , etc.). For example: .
  • Time lookups (hour, minute, second) are now supported by for all database backends. Support for backends other than SQLite was added but undocumented in Django 1.7.
  • You can specify the parameter of the aggregate in order to aggregate over non-numeric columns, such as .
  • Added the lookup to to allow querying the field by only the date portion.
  • Added the and database functions.
  • Added the database function, which returns the current date and time.
  • is now a subclass of Func() which allows s to be used on the right hand side of an expression, just like regular s. This allows registering some database functions like , , and as transforms.
  • now accepts an argument to allow Unicode characters in slugs.
  • Added support for referencing annotations in .
  • shows queries with substituted parameters on SQLite.
  • Query expressions can now be used when creating new model instances using , , and .

Requests and Responses¶

  • Unless is explicitly set, it now is determined by the current value of . Modifying the value of outside of the constructor will also modify the value of .
  • The debug view now shows details of chained exceptions on Python 3.
  • The default 40x error views now accept a second positional parameter, the exception that triggered the view.
  • View error handlers now support , commonly used with class-based views.
  • Exceptions raised by the method are now passed to the method of each middleware.
  • Request middleware can now set to to revert any changes made by previous middleware and return to using the .
  • The check in now raises a exception as opposed to returning an so that is invoked.
  • Added to fetch the originating port of the request.
  • Added the parameter to to allow passing keyword arguments to the call used to generate the response.
  • The now ignores 404s when the referer is equal to the requested URL. To circumvent the empty referer check already implemented, some Web bots set the referer to the requested URL.

Templates¶

  • Template tags created with the helper can now store results in a template variable by using the argument.
  • Added a method.
  • The django.template logger was added and includes the following messages:
    • A level message for missing context variables.
    • A level message for uncaught exceptions raised during the rendering of an when debug mode is off (helpful since silences the exception and returns an empty string).
  • The template tag supports storing the output in a variable using ‘as’.
  • can now be used as a context manager.
  • Django template loaders can now extend templates recursively.
  • The debug page template postmortem now include output from each engine that is installed.
  • Debug page integration for custom template engines was added.
  • The backend gained the ability to register libraries and builtins explicitly through the template .
  • The and filters were improved to deal with leap years when given large time spans.
  • The tag now caches parsed templates objects during template rendering, speeding up reuse in places such as for loops.

Tests¶

  • Added the method to test client responses to give access to the response body as JSON.
  • Added the method to the test client. Use this method to simulate the effect of a user logging into the site while skipping the authentication and verification steps of .

URLs¶

  • Regular expression lookaround assertions are now allowed in URL patterns.
  • The application namespace can now be set using an attribute on the included module or object. It can also be set by passing a 2-tuple of (<list of patterns>, <application namespace>) as the first argument to .
  • System checks have been added for common URL pattern mistakes.

Backwards incompatible changes in 1.9¶

Warning

In addition to the changes outlined in this section, be sure to review the Features removed in 1.9 for the features that have reached the end of their deprecation cycle and therefore been removed. If you haven’t updated your code within the deprecation timeline for a given feature, its removal may appear as a backwards incompatible change.

Database backend API¶

  • A couple of new tests rely on the ability of the backend to introspect column defaults (returning the result as ). You can set the database feature to if your backend doesn’t implement this. You may want to review the implementation on the backends that Django includes for reference (#24245).

  • Registering a global adapter or converter at the level of the DB-API module to handle time zone information of values passed as query parameters or returned as query results on databases that don’t support time zones is discouraged. It can conflict with other libraries.

    The recommended way to add a time zone to values fetched from the database is to register a converter for in .

    The database feature was removed. Database backends that set it must register a converter instead, as explained above.

  • The methods were renamed to to mirror the methods.

  • To use the new lookup, third-party database backends may need to implement the method.

  • The method was added. It calls the existing method. This method is overridden by the SQLite backend to add time lookups (hour, minute, second) to , and may be needed by third-party database backends.

  • The method (not to be confused with mentioned above) has been removed. This method served to format dates on Oracle long before 1.0, but hasn’t been overridden by any core backend in years and hasn’t been called anywhere in Django’s code or tests.

  • In order to support test parallelization, you must implement the method and set . You may have to adjust .

Default settings that were tuples are now lists¶

The default settings in were a combination of lists and tuples. All settings that were formerly tuples are now lists.

attribute on template loaders is removed¶

Django template loaders previously required an attribute to be defined. If a loader was configured in the template settings and this attribute was , the loader would be silently ignored. In practice, this was only used by the egg loader to detect if setuptools was installed. The attribute is now removed and the egg loader instead fails at runtime if setuptools is not installed.

Filesystem-based template loaders catch more specific exceptions¶

When using the or template loaders, earlier versions of Django raised a error if a template source existed but was unreadable. This could happen under many circumstances, such as if Django didn’t have permissions to open the file, or if the template source was a directory. Now, Django only silences the exception if the template source does not exist. All other situations result in the original being raised.

HTTP redirects no longer forced to absolute URIs¶

Relative redirects are no longer converted to absolute URIs. RFC 2616 required the header in redirect responses to be an absolute URI, but it has been superseded by RFC 7231 which allows relative URIs in , recognizing the actual practice of user agents, almost all of which support them.

Consequently, the expected URLs passed to should generally no longer include the scheme and domain part of the URLs. For example, should be replaced by (unless the redirection specifically contained an absolute URL, of course).

In the rare case that you need the old behavior (discovered with an ancient version of Apache with that interprets a relative redirect as an “internal redirect”), you can restore it by writing a custom middleware:

classLocationHeaderFix(object):defprocess_response(self,request,response):if'Location'inresponse:response['Location']=request.build_absolute_uri(response['Location'])returnresponse

Dropped support for PostgreSQL 9.0¶

Upstream support for PostgreSQL 9.0 ended in September 2015. As a consequence, Django 1.9 sets 9.1 as the minimum PostgreSQL version it officially supports.

Dropped support for Oracle 11.1¶

Upstream support for Oracle 11.1 ended in August 2015. As a consequence, Django 1.9 sets 11.2 as the minimum Oracle version it officially supports.

Template and are removed¶

In previous versions of Django, when a template engine was initialized with debug as , an instance of or was set as the origin attribute on the template object. These classes have been combined into and is now always set regardless of the engine debug setting. For a minimal level of backwards compatibility, the old class names will be kept as aliases to the new class until Django 2.0.

Changes to the default logging configuration¶

To make it easier to write custom logging configurations, Django’s default logging configuration no longer defines and loggers. Instead, it defines a single logger, filtered at the level, with two handlers:

  • : filtered at the level and only active if .
  • : filtered at the level and only active if .

If you aren’t overriding Django’s default logging, you should see minimal changes in behavior, but you might see some new logging to the console, for example.

If you are overriding Django’s default logging, you should check to see how your configuration merges with the new defaults.

details in error reporting¶

It was redundant to display the full details of the each time it appeared as a stack frame variable in the HTML version of the debug page and error email. Thus, the HTTP request will now display the same standard representation as other variables (). As a result, the method and the undocumented function were removed.

The contents of the text version of the email were modified to provide a traceback of the same structure as in the case of AJAX requests. The traceback details are rendered by the method.

Removal of time zone aware global adapters and converters for datetimes¶

Django no longer registers global adapters and converters for managing time zone information on values sent to the database as query parameters or read from the database in query results. This change affects projects that meet all the following conditions:

  • The setting is .
  • The database is SQLite, MySQL, Oracle, or a third-party database that doesn’t support time zones. In doubt, you can check the value of .
  • The code queries the database outside of the ORM, typically with .

If you’re passing aware parameters to such queries, you should turn them into naive datetimes in UTC:

If you fail to do so, the conversion will be performed as in earlier versions (with a deprecation warning) up until Django 1.11. Django 2.0 won’t perform any conversion, which may result in data corruption.

If you’re reading values from the results, they will be naive instead of aware. You can compensate as follows:

You don’t need any of this if you’re querying the database through the ORM, even if you’re using queries. The ORM takes care of managing time zone information.

fromdjango.utilsimporttimezoneparam=timezone.make_naive(param,timezone.utc)
fromdjango.utilsimporttimezonevalue=timezone.make_aware(value,timezone.utc)

Template tag modules are imported when templates are configured¶

The backend now performs discovery on installed template tag modules when instantiated. This update enables libraries to be provided explicitly via the key of when defining a backend. Import or syntax errors in template tag modules now fail early at instantiation time rather than when a template with a tag is first compiled.

is removed¶

Although it was a private API, projects commonly used

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *