2009-11-15 03:13:33 +08:00
|
|
|
.. _releases-1.2:
|
2009-10-20 05:48:06 +08:00
|
|
|
|
2009-11-15 03:13:33 +08:00
|
|
|
============================================
|
|
|
|
Django 1.2 release notes — UNDER DEVELOPMENT
|
|
|
|
============================================
|
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
This page documents release notes for the as-yet-unreleased Django 1.2. As such,
|
|
|
|
it's tentative and subject to change. It provides up-to-date information for
|
2009-11-15 03:13:33 +08:00
|
|
|
those who are following trunk.
|
|
|
|
|
2009-11-23 21:44:24 +08:00
|
|
|
Django 1.2 includes a number of nifty `new features`_, lots of bug
|
2010-01-10 01:55:28 +08:00
|
|
|
fixes and an easy upgrade path from Django 1.1.
|
2009-11-23 21:44:24 +08:00
|
|
|
|
|
|
|
.. _new features: `What's new in Django 1.2`_
|
|
|
|
|
2009-11-15 03:13:33 +08:00
|
|
|
.. _backwards-incompatible-changes-1.2:
|
|
|
|
|
|
|
|
Backwards-incompatible changes in 1.2
|
|
|
|
=====================================
|
2009-10-20 05:48:06 +08:00
|
|
|
|
Fixed #9977 - CsrfMiddleware gets template tag added, session dependency removed, and turned on by default.
This is a large change to CSRF protection for Django. It includes:
* removing the dependency on the session framework.
* deprecating CsrfResponseMiddleware, and replacing with a core template tag.
* turning on CSRF protection by default by adding CsrfViewMiddleware to
the default value of MIDDLEWARE_CLASSES.
* protecting all contrib apps (whatever is in settings.py)
using a decorator.
For existing users of the CSRF functionality, it should be a seamless update,
but please note that it includes DEPRECATION of features in Django 1.1,
and there are upgrade steps which are detailed in the docs.
Many thanks to 'Glenn' and 'bthomas', who did a lot of the thinking and work
on the patch, and to lots of other people including Simon Willison and
Russell Keith-Magee who refined the ideas.
Details of the rationale for these changes is found here:
http://code.djangoproject.com/wiki/CsrfProtection
As of this commit, the CSRF code is mainly in 'contrib'. The code will be
moved to core in a separate commit, to make the changeset as readable as
possible.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11660 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-10-27 07:23:07 +08:00
|
|
|
CSRF Protection
|
|
|
|
---------------
|
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
We've made large changes to the way CSRF protection works, detailed in
|
|
|
|
:ref:`the CSRF documentaton <ref-contrib-csrf>`. Here are the major changes you
|
|
|
|
should be aware of:
|
Fixed #9977 - CsrfMiddleware gets template tag added, session dependency removed, and turned on by default.
This is a large change to CSRF protection for Django. It includes:
* removing the dependency on the session framework.
* deprecating CsrfResponseMiddleware, and replacing with a core template tag.
* turning on CSRF protection by default by adding CsrfViewMiddleware to
the default value of MIDDLEWARE_CLASSES.
* protecting all contrib apps (whatever is in settings.py)
using a decorator.
For existing users of the CSRF functionality, it should be a seamless update,
but please note that it includes DEPRECATION of features in Django 1.1,
and there are upgrade steps which are detailed in the docs.
Many thanks to 'Glenn' and 'bthomas', who did a lot of the thinking and work
on the patch, and to lots of other people including Simon Willison and
Russell Keith-Magee who refined the ideas.
Details of the rationale for these changes is found here:
http://code.djangoproject.com/wiki/CsrfProtection
As of this commit, the CSRF code is mainly in 'contrib'. The code will be
moved to core in a separate commit, to make the changeset as readable as
possible.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11660 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-10-27 07:23:07 +08:00
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
* ``CsrfResponseMiddleware`` and ``CsrfMiddleware`` have been deprecated and
|
2009-12-03 22:48:47 +08:00
|
|
|
will be removed completely in Django 1.4, in favor of a template tag that
|
Fixed #9977 - CsrfMiddleware gets template tag added, session dependency removed, and turned on by default.
This is a large change to CSRF protection for Django. It includes:
* removing the dependency on the session framework.
* deprecating CsrfResponseMiddleware, and replacing with a core template tag.
* turning on CSRF protection by default by adding CsrfViewMiddleware to
the default value of MIDDLEWARE_CLASSES.
* protecting all contrib apps (whatever is in settings.py)
using a decorator.
For existing users of the CSRF functionality, it should be a seamless update,
but please note that it includes DEPRECATION of features in Django 1.1,
and there are upgrade steps which are detailed in the docs.
Many thanks to 'Glenn' and 'bthomas', who did a lot of the thinking and work
on the patch, and to lots of other people including Simon Willison and
Russell Keith-Magee who refined the ideas.
Details of the rationale for these changes is found here:
http://code.djangoproject.com/wiki/CsrfProtection
As of this commit, the CSRF code is mainly in 'contrib'. The code will be
moved to core in a separate commit, to make the changeset as readable as
possible.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11660 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-10-27 07:23:07 +08:00
|
|
|
should be inserted into forms.
|
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
* All contrib apps use a ``csrf_protect`` decorator to protect the view. This
|
|
|
|
requires the use of the csrf_token template tag in the template. If you
|
2009-12-03 22:48:47 +08:00
|
|
|
have used custom templates for contrib views, you MUST READ THE :ref:`UPGRADE
|
|
|
|
INSTRUCTIONS <ref-csrf-upgrading-notes>` to fix those templates.
|
2009-10-27 20:11:56 +08:00
|
|
|
|
Fixed #9977 - CsrfMiddleware gets template tag added, session dependency removed, and turned on by default.
This is a large change to CSRF protection for Django. It includes:
* removing the dependency on the session framework.
* deprecating CsrfResponseMiddleware, and replacing with a core template tag.
* turning on CSRF protection by default by adding CsrfViewMiddleware to
the default value of MIDDLEWARE_CLASSES.
* protecting all contrib apps (whatever is in settings.py)
using a decorator.
For existing users of the CSRF functionality, it should be a seamless update,
but please note that it includes DEPRECATION of features in Django 1.1,
and there are upgrade steps which are detailed in the docs.
Many thanks to 'Glenn' and 'bthomas', who did a lot of the thinking and work
on the patch, and to lots of other people including Simon Willison and
Russell Keith-Magee who refined the ideas.
Details of the rationale for these changes is found here:
http://code.djangoproject.com/wiki/CsrfProtection
As of this commit, the CSRF code is mainly in 'contrib'. The code will be
moved to core in a separate commit, to make the changeset as readable as
possible.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11660 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-10-27 07:23:07 +08:00
|
|
|
* ``CsrfViewMiddleware`` is included in :setting:`MIDDLEWARE_CLASSES` by
|
2010-01-10 01:55:28 +08:00
|
|
|
default. This turns on CSRF protection by default, so views that accept
|
|
|
|
POST requests need to be written to work with the middleware. Instructions
|
Fixed #9977 - CsrfMiddleware gets template tag added, session dependency removed, and turned on by default.
This is a large change to CSRF protection for Django. It includes:
* removing the dependency on the session framework.
* deprecating CsrfResponseMiddleware, and replacing with a core template tag.
* turning on CSRF protection by default by adding CsrfViewMiddleware to
the default value of MIDDLEWARE_CLASSES.
* protecting all contrib apps (whatever is in settings.py)
using a decorator.
For existing users of the CSRF functionality, it should be a seamless update,
but please note that it includes DEPRECATION of features in Django 1.1,
and there are upgrade steps which are detailed in the docs.
Many thanks to 'Glenn' and 'bthomas', who did a lot of the thinking and work
on the patch, and to lots of other people including Simon Willison and
Russell Keith-Magee who refined the ideas.
Details of the rationale for these changes is found here:
http://code.djangoproject.com/wiki/CsrfProtection
As of this commit, the CSRF code is mainly in 'contrib'. The code will be
moved to core in a separate commit, to make the changeset as readable as
possible.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11660 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-10-27 07:23:07 +08:00
|
|
|
on how to do this are found in the CSRF docs.
|
|
|
|
|
2009-10-27 08:36:34 +08:00
|
|
|
* All of the CSRF has moved from contrib to core (with backwards compatible
|
|
|
|
imports in the old locations, which are deprecated).
|
|
|
|
|
2009-12-10 06:40:36 +08:00
|
|
|
:ttag:`if` tag changes
|
|
|
|
----------------------
|
|
|
|
|
|
|
|
Due to new features in the :ttag:`if` template tag, it no longer accepts 'and',
|
2010-01-10 01:55:28 +08:00
|
|
|
'or' and 'not' as valid **variable** names. Previously, that worked in some
|
|
|
|
cases even though these strings were normally treated as keywords. Now, the
|
|
|
|
keyword status is always enforced, and template code such as ``{% if not %}`` or
|
2010-01-12 21:14:32 +08:00
|
|
|
``{% if and %}`` will throw a ``TemplateSyntaxError``. Also, ``in`` is a new
|
|
|
|
keyword and so is not a valid variable name in this context.
|
2009-12-10 06:40:36 +08:00
|
|
|
|
2009-12-03 22:58:58 +08:00
|
|
|
``LazyObject``
|
|
|
|
--------------
|
2009-10-20 05:48:06 +08:00
|
|
|
|
|
|
|
``LazyObject`` is an undocumented utility class used for lazily wrapping other
|
2010-01-10 01:55:28 +08:00
|
|
|
objects of unknown type. In Django 1.1 and earlier, it handled introspection in
|
2009-10-20 05:48:06 +08:00
|
|
|
a non-standard way, depending on wrapped objects implementing a public method
|
|
|
|
``get_all_members()``. Since this could easily lead to name clashes, it has been
|
|
|
|
changed to use the standard method, involving ``__members__`` and ``__dir__()``.
|
2010-01-10 01:55:28 +08:00
|
|
|
If you used ``LazyObject`` in your own code and implemented the
|
2009-10-20 05:48:06 +08:00
|
|
|
``get_all_members()`` method for wrapped objects, you need to make the following
|
|
|
|
changes:
|
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
* If your class does not have special requirements for introspection (i.e., you
|
2009-10-20 05:48:06 +08:00
|
|
|
have not implemented ``__getattr__()`` or other methods that allow for
|
|
|
|
attributes not discoverable by normal mechanisms), you can simply remove the
|
2010-01-10 01:55:28 +08:00
|
|
|
``get_all_members()`` method. The default implementation on ``LazyObject``
|
2009-10-20 05:48:06 +08:00
|
|
|
will do the right thing.
|
|
|
|
|
|
|
|
* If you have more complex requirements for introspection, first rename the
|
2010-01-10 01:55:28 +08:00
|
|
|
``get_all_members()`` method to ``__dir__()``. This is the standard method,
|
|
|
|
from Python 2.6 onwards, for supporting introspection. If you require
|
2009-10-20 05:48:06 +08:00
|
|
|
support for Python < 2.6, add the following code to the class::
|
|
|
|
|
|
|
|
__members__ = property(lambda self: self.__dir__())
|
2009-11-15 03:13:33 +08:00
|
|
|
|
2009-12-22 23:18:51 +08:00
|
|
|
Specifying databases
|
|
|
|
--------------------
|
|
|
|
|
|
|
|
Prior to Django 1.1, Django used a number of settings to control access to a
|
|
|
|
single database. Django 1.2 introduces support for multiple databases, and as
|
|
|
|
a result, the way you define database settings has changed.
|
|
|
|
|
|
|
|
Any existing Django settings file will continue to work as expected until
|
2010-01-10 01:55:28 +08:00
|
|
|
Django 1.4. Until then, old-style database settings will be automatically
|
|
|
|
translated to the new-style format.
|
2009-12-22 23:18:51 +08:00
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
In the old-style (pre 1.2) format, you had a number of ``DATABASE_`` settings
|
|
|
|
in your settings file. For example::
|
2009-12-22 23:18:51 +08:00
|
|
|
|
|
|
|
DATABASE_NAME = 'test_db'
|
2010-01-06 16:16:07 +08:00
|
|
|
DATABASE_ENGINE = 'postgresql_psycopg2'
|
2009-12-22 23:18:51 +08:00
|
|
|
DATABASE_USER = 'myusername'
|
|
|
|
DATABASE_PASSWORD = 's3krit'
|
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
These settings are now in a dictionary named :setting:`DATABASES`. Each item in
|
|
|
|
the dictionary corresponds to a single database connection, with the name
|
|
|
|
``'default'`` describing the default database connection. The setting names
|
|
|
|
have also been shortened. The previous sample settings would now look like this::
|
2009-12-22 23:18:51 +08:00
|
|
|
|
|
|
|
DATABASES = {
|
|
|
|
'default': {
|
|
|
|
'NAME': 'test_db',
|
2010-01-06 16:16:07 +08:00
|
|
|
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
2009-12-22 23:18:51 +08:00
|
|
|
'USER': 'myusername',
|
|
|
|
'PASSWORD': 's3krit',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
This affects the following settings:
|
|
|
|
|
|
|
|
========================================= ==========================
|
|
|
|
Old setting New Setting
|
|
|
|
========================================= ==========================
|
|
|
|
:setting:`DATABASE_ENGINE` :setting:`ENGINE`
|
|
|
|
:setting:`DATABASE_HOST` :setting:`HOST`
|
|
|
|
:setting:`DATABASE_NAME` :setting:`NAME`
|
|
|
|
:setting:`DATABASE_OPTIONS` :setting:`OPTIONS`
|
|
|
|
:setting:`DATABASE_PASSWORD` :setting:`PASSWORD`
|
|
|
|
:setting:`DATABASE_PORT` :setting:`PORT`
|
|
|
|
:setting:`DATABASE_USER` :setting:`USER`
|
|
|
|
:setting:`TEST_DATABASE_CHARSET` :setting:`TEST_CHARSET`
|
|
|
|
:setting:`TEST_DATABASE_COLLATION` :setting:`TEST_COLLATION`
|
|
|
|
:setting:`TEST_DATABASE_NAME` :setting:`TEST_NAME`
|
|
|
|
========================================= ==========================
|
|
|
|
|
|
|
|
These changes are also required if you have manually created a database
|
|
|
|
connection using ``DatabaseWrapper()`` from your database backend of choice.
|
|
|
|
|
|
|
|
In addition to the change in structure, Django 1.2 removes the special
|
|
|
|
handling for the built-in database backends. All database backends
|
|
|
|
must now be specified by a fully qualified module name (i.e.,
|
2010-01-06 16:16:07 +08:00
|
|
|
``django.db.backends.postgresql_psycopg2``, rather than just
|
2009-12-22 23:18:51 +08:00
|
|
|
``postgresql_psycopg2``).
|
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
``__dict__`` on model instances
|
2009-12-22 23:18:51 +08:00
|
|
|
-------------------------------
|
|
|
|
|
|
|
|
Historically, the ``__dict__`` attribute of a model instance has only contained
|
|
|
|
attributes corresponding to the fields on a model.
|
|
|
|
|
|
|
|
In order to support multiple database configurations, Django 1.2 has
|
|
|
|
added a ``_state`` attribute to object instances. This attribute will
|
|
|
|
appear in ``__dict__`` for a model instance. If your code relies on
|
|
|
|
iterating over __dict__ to obtain a list of fields, you must now
|
2010-01-10 01:55:28 +08:00
|
|
|
filter the ``_state`` attribute of out ``__dict__``.
|
2009-12-22 23:18:51 +08:00
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
``get_db_prep_*()`` methods on ``Field``
|
|
|
|
----------------------------------------
|
2009-12-22 23:18:51 +08:00
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
Prior to 1.2, a custom ``Field`` had the option of defining several
|
2009-12-22 23:18:51 +08:00
|
|
|
functions to support conversion of Python values into
|
|
|
|
database-compatible values. A custom field might look something like::
|
|
|
|
|
|
|
|
class CustomModelField(models.Field):
|
|
|
|
# ...
|
|
|
|
|
|
|
|
def get_db_prep_save(self, value):
|
|
|
|
# ...
|
|
|
|
|
|
|
|
def get_db_prep_value(self, value):
|
|
|
|
# ...
|
|
|
|
|
|
|
|
def get_db_prep_lookup(self, lookup_type, value):
|
|
|
|
# ...
|
|
|
|
|
|
|
|
In 1.2, these three methods have undergone a change in prototype, and
|
|
|
|
two extra methods have been introduced::
|
|
|
|
|
|
|
|
class CustomModelField(models.Field):
|
|
|
|
# ...
|
|
|
|
|
|
|
|
def get_prep_value(self, value):
|
|
|
|
# ...
|
|
|
|
|
|
|
|
def get_prep_lookup(self, lookup_type, value):
|
|
|
|
# ...
|
|
|
|
|
|
|
|
def get_db_prep_save(self, value, connection):
|
|
|
|
# ...
|
|
|
|
|
|
|
|
def get_db_prep_value(self, value, connection, prepared=False):
|
|
|
|
# ...
|
|
|
|
|
|
|
|
def get_db_prep_lookup(self, lookup_type, value, connection, prepared=False):
|
|
|
|
# ...
|
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
These changes are required to support multiple databases --
|
2009-12-22 23:18:51 +08:00
|
|
|
``get_db_prep_*`` can no longer make any assumptions regarding the
|
|
|
|
database for which it is preparing. The ``connection`` argument now
|
|
|
|
provides the preparation methods with the specific connection for
|
|
|
|
which the value is being prepared.
|
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
The two new methods exist to differentiate general data-preparation
|
|
|
|
requirements from requirements that are database-specific. The
|
|
|
|
``prepared`` argument is used to indicate to the database-preparation
|
2009-12-22 23:18:51 +08:00
|
|
|
methods whether generic value preparation has been performed. If
|
|
|
|
an unprepared (i.e., ``prepared=False``) value is provided to the
|
|
|
|
``get_db_prep_*()`` calls, they should invoke the corresponding
|
|
|
|
``get_prep_*()`` calls to perform generic data preparation.
|
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
We've provided conversion functions that will transparently
|
2009-12-22 23:18:51 +08:00
|
|
|
convert functions adhering to the old prototype into functions
|
2010-01-10 01:55:28 +08:00
|
|
|
compatible with the new prototype. However, these conversion functions
|
|
|
|
will be removed in Django 1.4, so you should upgrade your ``Field``
|
|
|
|
definitions to use the new prototype now, just to get it over with.
|
2009-12-22 23:18:51 +08:00
|
|
|
|
|
|
|
If your ``get_db_prep_*()`` methods made no use of the database
|
|
|
|
connection, you should be able to upgrade by renaming
|
|
|
|
``get_db_prep_value()`` to ``get_prep_value()`` and
|
|
|
|
``get_db_prep_lookup()`` to ``get_prep_lookup()`. If you require
|
|
|
|
database specific conversions, then you will need to provide an
|
|
|
|
implementation ``get_db_prep_*`` that uses the ``connection``
|
|
|
|
argument to resolve database-specific values.
|
|
|
|
|
2009-12-14 20:08:23 +08:00
|
|
|
Stateful template tags
|
|
|
|
----------------------
|
|
|
|
|
|
|
|
Template tags that store rendering state on the node itself may experience
|
|
|
|
problems if they are used with the new :ref:`cached
|
|
|
|
template loader<template-loaders>`.
|
|
|
|
|
|
|
|
All of the built-in Django template tags are safe to use with the cached
|
|
|
|
loader, but if you're using custom template tags that come from third
|
2010-01-10 01:55:28 +08:00
|
|
|
party packages, or from your own code, you should ensure that the
|
2009-12-14 20:08:23 +08:00
|
|
|
``Node`` implementation for each tag is thread-safe. For more
|
|
|
|
information, see
|
|
|
|
:ref:`template tag thread safety considerations<template_tag_thread_safety>`.
|
2009-12-03 22:58:58 +08:00
|
|
|
|
2010-01-04 02:52:25 +08:00
|
|
|
Test runner exit status code
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
The exit status code of the test runners (``tests/runtests.py`` and ``python
|
2010-01-10 01:55:28 +08:00
|
|
|
manage.py test``) no longer represents the number of failed tests, because a
|
|
|
|
failure of 256 or more tests resulted in a wrong exit status code. The exit
|
2010-01-04 02:52:25 +08:00
|
|
|
status code for the test runner is now 0 for success (no failing tests) and 1
|
2010-01-10 01:55:28 +08:00
|
|
|
for any number of test failures. If needed, the number of test failures can be
|
2010-01-04 02:52:25 +08:00
|
|
|
found at the end of the test runner's output.
|
|
|
|
|
2009-11-15 03:13:33 +08:00
|
|
|
.. _deprecated-features-1.2:
|
|
|
|
|
|
|
|
Features deprecated in 1.2
|
|
|
|
==========================
|
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
CSRF response-rewriting middleware
|
2009-12-03 22:48:47 +08:00
|
|
|
----------------------------------
|
|
|
|
|
|
|
|
``CsrfResponseMiddleware``, the middleware that automatically inserted CSRF
|
|
|
|
tokens into POST forms in outgoing pages, has been deprecated in favor of a
|
|
|
|
template tag method (see above), and will be removed completely in Django
|
|
|
|
1.4. ``CsrfMiddleware``, which includes the functionality of
|
2010-01-10 01:55:28 +08:00
|
|
|
``CsrfResponseMiddleware`` and ``CsrfViewMiddleware``, has likewise been
|
2009-12-03 22:48:47 +08:00
|
|
|
deprecated.
|
|
|
|
|
|
|
|
Also, the CSRF module has moved from contrib to core, and the old imports are
|
|
|
|
deprecated, as described in the :ref:`upgrading notes <ref-csrf-upgrading-notes>`.
|
|
|
|
|
|
|
|
``SMTPConnection``
|
|
|
|
------------------
|
|
|
|
|
2009-12-03 22:58:58 +08:00
|
|
|
The ``SMTPConnection`` class has been deprecated in favor of a generic
|
2010-01-10 01:55:28 +08:00
|
|
|
e-mail backend API. Old code that explicitly instantiated an instance
|
2009-12-03 22:58:58 +08:00
|
|
|
of an SMTPConnection::
|
|
|
|
|
|
|
|
from django.core.mail import SMTPConnection
|
|
|
|
connection = SMTPConnection()
|
|
|
|
messages = get_notification_email()
|
|
|
|
connection.send_messages(messages)
|
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
...should now call :meth:`~django.core.mail.get_connection()` to
|
2009-12-03 22:58:58 +08:00
|
|
|
instantiate a generic e-mail connection::
|
|
|
|
|
|
|
|
from django.core.mail import get_connection
|
|
|
|
connection = get_connection()
|
|
|
|
messages = get_notification_email()
|
|
|
|
connection.send_messages(messages)
|
|
|
|
|
|
|
|
Depending on the value of the :setting:`EMAIL_BACKEND` setting, this
|
|
|
|
may not return an SMTP connection. If you explicitly require an SMTP
|
|
|
|
connection with which to send e-mail, you can explicitly request an
|
|
|
|
SMTP connection::
|
|
|
|
|
|
|
|
from django.core.mail import get_connection
|
2010-01-04 20:05:04 +08:00
|
|
|
connection = get_connection('django.core.mail.backends.smtp.EmailBackend')
|
2009-12-03 22:58:58 +08:00
|
|
|
messages = get_notification_email()
|
|
|
|
connection.send_messages(messages)
|
|
|
|
|
|
|
|
If your call to construct an instance of ``SMTPConnection`` required
|
|
|
|
additional arguments, those arguments can be passed to the
|
|
|
|
:meth:`~django.core.mail.get_connection()` call::
|
|
|
|
|
2010-01-04 20:05:04 +08:00
|
|
|
connection = get_connection('django.core.mail.backends.smtp.EmailBackend', hostname='localhost', port=1234)
|
2009-12-14 20:08:23 +08:00
|
|
|
|
2009-12-10 00:57:23 +08:00
|
|
|
User Messages API
|
|
|
|
-----------------
|
|
|
|
|
2009-12-14 20:08:23 +08:00
|
|
|
The API for storing messages in the user ``Message`` model (via
|
2009-12-10 00:57:23 +08:00
|
|
|
``user.message_set.create``) is now deprecated and will be removed in Django
|
|
|
|
1.4 according to the standard :ref:`release process <internals-release-process>`.
|
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
To upgrade your code, you need to replace any instances of this::
|
2009-12-10 00:57:23 +08:00
|
|
|
|
|
|
|
user.message_set.create('a message')
|
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
...with the following::
|
2009-12-10 00:57:23 +08:00
|
|
|
|
|
|
|
from django.contrib import messages
|
|
|
|
messages.add_message(request, messages.INFO, 'a message')
|
|
|
|
|
2009-12-14 20:08:23 +08:00
|
|
|
Additionally, if you make use of the method, you need to replace the
|
2009-12-10 00:57:23 +08:00
|
|
|
following::
|
|
|
|
|
|
|
|
for message in user.get_and_delete_messages():
|
|
|
|
...
|
2009-12-14 20:08:23 +08:00
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
...with::
|
2009-12-10 00:57:23 +08:00
|
|
|
|
|
|
|
from django.contrib import messages
|
|
|
|
for message in messages.get_messages(request):
|
|
|
|
...
|
2009-12-14 20:08:23 +08:00
|
|
|
|
|
|
|
For more information, see the full
|
|
|
|
:ref:`messages documentation <ref-contrib-messages>`. You should begin to
|
2009-12-10 00:57:23 +08:00
|
|
|
update your code to use the new API immediately.
|
2009-11-23 21:44:24 +08:00
|
|
|
|
2009-12-23 01:58:49 +08:00
|
|
|
Date format helper functions
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
``django.utils.translation.get_date_formats()`` and
|
|
|
|
``django.utils.translation.get_partial_date_formats()`` have been deprecated
|
2010-01-10 01:55:28 +08:00
|
|
|
in favor of the appropriate calls to ``django.utils.formats.get_format()``,
|
|
|
|
which is locale-aware when :setting:`USE_L10N` is set to ``True``, and falls
|
2009-12-23 01:58:49 +08:00
|
|
|
back to default settings if set to ``False``.
|
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
To get the different date formats, instead of writing this::
|
2009-12-23 01:58:49 +08:00
|
|
|
|
|
|
|
from django.utils.translation import get_date_formats
|
|
|
|
date_format, datetime_format, time_format = get_date_formats()
|
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
...use::
|
2009-12-23 01:58:49 +08:00
|
|
|
|
|
|
|
from django.utils import formats
|
|
|
|
date_format = formats.get_format('DATE_FORMAT')
|
|
|
|
datetime_format = formats.get_format('DATETIME_FORMAT')
|
|
|
|
time_format = formats.get_format('TIME_FORMAT')
|
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
Or, when directly formatting a date value::
|
2009-12-23 01:58:49 +08:00
|
|
|
|
|
|
|
from django.utils import formats
|
|
|
|
value_formatted = formats.date_format(value, 'DATETIME_FORMAT')
|
|
|
|
|
|
|
|
The same applies to the globals found in ``django.forms.fields``:
|
|
|
|
|
|
|
|
* ``DEFAULT_DATE_INPUT_FORMATS``
|
|
|
|
* ``DEFAULT_TIME_INPUT_FORMATS``
|
|
|
|
* ``DEFAULT_DATETIME_INPUT_FORMATS``
|
|
|
|
|
|
|
|
Use ``django.utils.formats.get_format()`` to get the appropriate formats.
|
|
|
|
|
2010-01-12 22:58:47 +08:00
|
|
|
email_re
|
|
|
|
--------
|
|
|
|
|
|
|
|
An undocumented regex for validating email addresses has been moved from
|
|
|
|
django.form.fields to django.core.validators. You will need to update
|
|
|
|
your imports if you are using it.
|
|
|
|
|
2009-11-23 21:44:24 +08:00
|
|
|
What's new in Django 1.2
|
|
|
|
========================
|
|
|
|
|
|
|
|
CSRF support
|
|
|
|
------------
|
|
|
|
|
|
|
|
Django now has much improved protection against :ref:`Cross-Site
|
|
|
|
Request Forgery (CSRF) attacks<ref-contrib-csrf>`. This type of attack
|
|
|
|
occurs when a malicious Web site contains a link, a form button or
|
2010-01-10 01:55:28 +08:00
|
|
|
some JavaScript that is intended to perform some action on your Web
|
2009-11-23 21:44:24 +08:00
|
|
|
site, using the credentials of a logged-in user who visits the
|
2010-01-10 01:55:28 +08:00
|
|
|
malicious site in their browser. A related type of attack, "login
|
|
|
|
CSRF," where an attacking site tricks a user's browser into logging
|
2009-11-23 21:44:24 +08:00
|
|
|
into a site with someone else's credentials, is also covered.
|
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
E-mail backends
|
2009-12-03 22:55:28 +08:00
|
|
|
---------------
|
2009-11-23 21:44:24 +08:00
|
|
|
|
2009-12-03 22:55:28 +08:00
|
|
|
You can now :ref:`configure the way that Django sends e-mail
|
|
|
|
<topic-email-backends>`. Instead of using SMTP to send all e-mail, you
|
|
|
|
can now choose a configurable e-mail backend to send messages. If your
|
2009-11-23 21:44:24 +08:00
|
|
|
hosting provider uses a sandbox or some other non-SMTP technique for
|
2009-12-03 22:55:28 +08:00
|
|
|
sending mail, you can now construct an e-mail backend that will allow
|
2009-11-23 21:44:24 +08:00
|
|
|
Django's standard :ref:`mail sending methods<topics-email>` to use
|
|
|
|
those facilities.
|
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
This also makes it easier to debug mail sending. Django ships with
|
2009-12-03 22:55:28 +08:00
|
|
|
backend implementations that allow you to send e-mail to a
|
2009-11-23 21:44:24 +08:00
|
|
|
:ref:`file<topic-email-file-backend>`, to the
|
|
|
|
:ref:`console<topic-email-console-backend>`, or to
|
2010-01-10 01:55:28 +08:00
|
|
|
:ref:`memory<topic-email-memory-backend>`. You can even configure all
|
2009-12-03 22:55:28 +08:00
|
|
|
e-mail to be :ref:`thrown away<topic-email-dummy-backend>`.
|
2009-11-23 21:44:24 +08:00
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
Messages framework
|
2009-12-10 00:57:23 +08:00
|
|
|
------------------
|
|
|
|
|
|
|
|
Django now includes a robust and configurable :ref:`messages framework
|
|
|
|
<ref-contrib-messages>` with built-in support for cookie- and session-based
|
|
|
|
messaging, for both anonymous and authenticated clients. The messages framework
|
|
|
|
replaces the deprecated user message API and allows you to temporarily store
|
|
|
|
messages in one request and retrieve them for display in a subsequent request
|
|
|
|
(usually the next one).
|
2009-12-10 06:40:36 +08:00
|
|
|
|
2009-12-22 23:18:51 +08:00
|
|
|
Support for multiple databases
|
|
|
|
------------------------------
|
|
|
|
|
|
|
|
Django 1.2 adds the ability to use :ref:`more than one database
|
|
|
|
<topics-db-multi-db>` in your Django project. Queries can be
|
|
|
|
issued at a specific database with the `using()` method on
|
2010-01-10 01:55:28 +08:00
|
|
|
``QuerySet`` objects. Individual objects can be saved to a specific database
|
|
|
|
by providing a ``using`` argument when you call ``save()``.
|
2009-12-22 23:18:51 +08:00
|
|
|
|
2009-12-10 06:40:36 +08:00
|
|
|
'Smart' if tag
|
|
|
|
--------------
|
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
The :ttag:`if` tag has been upgraded to be much more powerful. First, we've
|
|
|
|
added support for comparison operators. No longer will you have to type:
|
2009-12-10 06:40:36 +08:00
|
|
|
|
|
|
|
.. code-block:: html+django
|
|
|
|
|
|
|
|
{% ifnotequal a b %}
|
|
|
|
...
|
|
|
|
{% endifnotequal %}
|
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
You can now do this::
|
2009-12-10 06:40:36 +08:00
|
|
|
|
|
|
|
.. code-block:: html+django
|
|
|
|
|
|
|
|
{% if a != b %}
|
|
|
|
...
|
|
|
|
{% endif %}
|
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
There's really no reason to use ``{% ifequal %}`` or ``{% ifnotequal %}``
|
|
|
|
anymore, unless you're the nostalgic type.
|
|
|
|
|
2009-12-10 06:40:36 +08:00
|
|
|
The operators supported are ``==``, ``!=``, ``<``, ``>``, ``<=``, ``>=`` and
|
|
|
|
``in``, all of which work like the Python operators, in addition to ``and``,
|
2010-01-10 01:55:28 +08:00
|
|
|
``or`` and ``not``, which were already supported.
|
2009-12-10 06:40:36 +08:00
|
|
|
|
|
|
|
Also, filters may now be used in the ``if`` expression. For example:
|
|
|
|
|
|
|
|
.. code-block:: html+django
|
|
|
|
|
|
|
|
<div
|
|
|
|
{% if user.email|lower == message.recipient|lower %}
|
|
|
|
class="highlight"
|
|
|
|
{% endif %}
|
|
|
|
>{{ message }}</div>
|
2009-12-14 20:08:23 +08:00
|
|
|
|
|
|
|
Template caching
|
|
|
|
----------------
|
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
In previous versions of Django, every time you rendered a template, it
|
2009-12-14 20:08:23 +08:00
|
|
|
would be reloaded from disk. In Django 1.2, you can use a :ref:`cached
|
2010-01-10 01:55:28 +08:00
|
|
|
template loader <template-loaders>` to load templates once, then
|
|
|
|
cache the result for every subsequent render. This can lead to a
|
2009-12-14 20:08:23 +08:00
|
|
|
significant performance improvement if your templates are broken into
|
|
|
|
lots of smaller subtemplates (using the ``{% extends %}`` or ``{%
|
|
|
|
include %}`` tags).
|
|
|
|
|
|
|
|
As a side effect, it is now much easier to support non-Django template
|
|
|
|
languages. For more details, see the :ref:`notes on supporting
|
|
|
|
non-Django template languages<topic-template-alternate-language>`.
|
2009-12-14 20:39:20 +08:00
|
|
|
|
|
|
|
Natural keys in fixtures
|
|
|
|
------------------------
|
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
Fixtures can now refer to remote objects using
|
2009-12-14 20:39:20 +08:00
|
|
|
:ref:`topics-serialization-natural-keys`. This lookup scheme is an
|
|
|
|
alternative to the normal primary-key based object references in a
|
2010-01-10 01:55:28 +08:00
|
|
|
fixture, improving readability and resolving problems referring to
|
2009-12-14 20:39:20 +08:00
|
|
|
objects whose primary key value may not be predictable or known.
|
|
|
|
|
2009-12-23 01:16:28 +08:00
|
|
|
``BigIntegerField``
|
|
|
|
-------------------
|
2009-12-22 21:41:51 +08:00
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
Models can now use a 64-bit :class:`~django.db.models.BigIntegerField` type.
|
2009-12-22 21:41:51 +08:00
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
Fast failure for tests
|
2009-12-22 21:41:51 +08:00
|
|
|
----------------------
|
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
Both the :djadmin:`test` subcommand of ``django-admin.py`` and the ``runtests.py``
|
|
|
|
script used to run Django's own test suite now support a ``--failfast`` option.
|
2010-01-04 02:52:25 +08:00
|
|
|
When specified, this option causes the test runner to exit after encountering
|
2010-01-10 01:55:28 +08:00
|
|
|
a failure instead of continuing with the test run. In addition, the handling
|
2010-01-04 02:52:25 +08:00
|
|
|
of ``Ctrl-C`` during a test run has been improved to trigger a graceful exit
|
2010-01-10 01:55:28 +08:00
|
|
|
from the test run that reports details of the tests that were run before the
|
|
|
|
interruption.
|
2009-12-23 01:58:49 +08:00
|
|
|
|
|
|
|
Improved localization
|
|
|
|
---------------------
|
|
|
|
|
|
|
|
Django's :ref:`internationalization framework <topics-i18n>` has been
|
2010-01-10 01:55:28 +08:00
|
|
|
expanded with locale-aware formatting and form processing. That means, if
|
2009-12-23 01:58:49 +08:00
|
|
|
enabled, dates and numbers on templates will be displayed using the format
|
|
|
|
specified for the current locale. Django will also use localized formats
|
2010-01-10 01:55:28 +08:00
|
|
|
when parsing data in forms. See
|
|
|
|
:ref:`Format localization <format-localization>` for more details.
|
2009-12-23 02:29:00 +08:00
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
``readonly_fields`` in ``ModelAdmin``
|
|
|
|
-------------------------------------
|
2009-12-23 02:29:00 +08:00
|
|
|
|
|
|
|
:attr:`django.contrib.admin.ModelAdmin.readonly_fields` has been added to
|
|
|
|
enable non-editable fields in add/change pages for models and inlines. Field
|
2010-01-10 01:55:28 +08:00
|
|
|
and calculated values can be displayed alongside editable fields.
|
2009-12-28 14:48:47 +08:00
|
|
|
|
|
|
|
Customizable syntax highlighting
|
|
|
|
--------------------------------
|
|
|
|
|
2010-01-10 01:55:28 +08:00
|
|
|
You can now use a ``DJANGO_COLORS`` environment variable to modify
|
2009-12-28 14:48:47 +08:00
|
|
|
or disable the colors used by ``django-admin.py`` to provide
|
|
|
|
:ref:`syntax highlighting <syntax-coloring>`.
|
2010-01-06 13:41:05 +08:00
|
|
|
|
|
|
|
Model validation
|
|
|
|
----------------
|
|
|
|
|
|
|
|
Model instances now have support for :ref:`validating their own data
|
2010-01-10 01:55:28 +08:00
|
|
|
<validating-objects>`, and both model and form fields now accept
|
2010-01-06 13:41:05 +08:00
|
|
|
configurable lists of :ref:`validators <ref-validators>` specifying
|
|
|
|
reusable, encapsulated validation behavior. Note, however, that
|
2010-01-10 01:55:28 +08:00
|
|
|
validation must still be performed explicitly. Simply invoking a model
|
2010-01-06 13:41:05 +08:00
|
|
|
instance's ``save()`` method will not perform any validation of the
|
|
|
|
instance's data.
|