Made a bunch of edits and typo corrections to 1.0-porting-guide.txt
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8966 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
1b39622327
commit
6008485b80
|
@ -212,7 +212,7 @@ URLs
|
||||||
Update your root ``urls.py``
|
Update your root ``urls.py``
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
If you are using the admin site you need to update your root ``urls.py``.
|
If you're using the admin site, you need to update your root ``urls.py``.
|
||||||
|
|
||||||
Old (0.96) ``urls.py``::
|
Old (0.96) ``urls.py``::
|
||||||
|
|
||||||
|
@ -246,14 +246,23 @@ Use ``django.forms`` instead of ``newforms``
|
||||||
|
|
||||||
Replace ``django.newforms`` with ``django.forms`` -- Django 1.0 renamed the
|
Replace ``django.newforms`` with ``django.forms`` -- Django 1.0 renamed the
|
||||||
``newforms`` module (introduced in 0.96) to plain old ``forms``. The
|
``newforms`` module (introduced in 0.96) to plain old ``forms``. The
|
||||||
``oldforms`` module was also removed removed.
|
``oldforms`` module was also removed.
|
||||||
|
|
||||||
If you are already using new forms all you have to do is change your import
|
If you're already using the ``newforms`` library, and you used our recommended
|
||||||
statement. Instead of ``from django import newforms as forms``, use ``from
|
``import`` statement syntax, all you have to do is change your import
|
||||||
django import forms``.
|
statements.
|
||||||
|
|
||||||
If you are using the old forms system, you will have to rewrite your forms. A
|
Old::
|
||||||
good place to start is the :ref:`forms documentation <topics-forms-index>`
|
|
||||||
|
from django import newforms as forms
|
||||||
|
|
||||||
|
New::
|
||||||
|
|
||||||
|
from django import forms
|
||||||
|
|
||||||
|
If you're using the old forms system (formerly known as ``django.forms`` and
|
||||||
|
``django.oldforms``), you'll have to rewrite your forms. A good place to start
|
||||||
|
is the :ref:`forms documentation <topics-forms-index>`
|
||||||
|
|
||||||
Handle uploaded files using the new API
|
Handle uploaded files using the new API
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
@ -268,7 +277,7 @@ Thus, in a view like::
|
||||||
f = request.FILES['file_field_name']
|
f = request.FILES['file_field_name']
|
||||||
...
|
...
|
||||||
|
|
||||||
You'd need to make the following changes:
|
...you'd need to make the following changes:
|
||||||
|
|
||||||
===================== =====================
|
===================== =====================
|
||||||
Old (0.96) New (1.0)
|
Old (0.96) New (1.0)
|
||||||
|
@ -284,7 +293,7 @@ Templates
|
||||||
Learn to love autoescaping
|
Learn to love autoescaping
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
By default, the templating system now automatically HTML-escapes the output of
|
By default, the template system now automatically HTML-escapes the output of
|
||||||
every variable. To learn more, see :ref:`automatic-html-escaping`.
|
every variable. To learn more, see :ref:`automatic-html-escaping`.
|
||||||
|
|
||||||
To disable auto-escaping for an individual variable, use the :tfilter:`safe`
|
To disable auto-escaping for an individual variable, use the :tfilter:`safe`
|
||||||
|
@ -352,18 +361,19 @@ Template tags
|
||||||
:ttag:`spaceless` tag
|
:ttag:`spaceless` tag
|
||||||
~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
The spaceless template tag removes *all* spaces between HTML tags instead of
|
The spaceless template tag now removes *all* spaces between HTML tags, instead
|
||||||
preserving a single space.
|
of preserving a single space.
|
||||||
|
|
||||||
Localflavor
|
Local flavors
|
||||||
-----------
|
-------------
|
||||||
|
|
||||||
US localflavor
|
U.S. local flavor
|
||||||
~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
``django.contrib.localflavor.usa`` has been renamed
|
``django.contrib.localflavor.usa`` has been renamed to
|
||||||
:mod:`django.contribg.localflavor.us`. This change was made to match the naming
|
:mod:`django.contrib.localflavor.us`. This change was made to match the naming
|
||||||
scheme of other local flavors.
|
scheme of other local flavors. To migrate your code, all you need to do is
|
||||||
|
change the imports.
|
||||||
|
|
||||||
Sessions
|
Sessions
|
||||||
--------
|
--------
|
||||||
|
@ -372,7 +382,7 @@ Getting a new session key
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
``SeesionBase.get_new_session_key()`` has been renamed to
|
``SeesionBase.get_new_session_key()`` has been renamed to
|
||||||
``_get_new_session_key()``; ``get_new_session_object()`` no longer exists.
|
``_get_new_session_key()``. ``get_new_session_object()`` no longer exists.
|
||||||
|
|
||||||
Fixtures
|
Fixtures
|
||||||
--------
|
--------
|
||||||
|
@ -390,7 +400,7 @@ Settings
|
||||||
Better exceptions
|
Better exceptions
|
||||||
~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
The old :exc:`EnvironmentError` was split into an :exc:`ImportError` raised when
|
The old :exc:`EnvironmentError` has split into an :exc:`ImportError` when
|
||||||
Django fails to find the settings module and a :exc:`RuntimeError` when you try
|
Django fails to find the settings module and a :exc:`RuntimeError` when you try
|
||||||
to reconfigure settings after having already used them
|
to reconfigure settings after having already used them
|
||||||
|
|
||||||
|
@ -401,15 +411,15 @@ The ``LOGIN_URL`` constant moved from ``django.contrib.auth`` into the
|
||||||
``settings`` module. Instead of using ``from django.contrib.auth import
|
``settings`` module. Instead of using ``from django.contrib.auth import
|
||||||
LOGIN_URL`` refer to :setting:`settings.LOGIN_URL <LOGIN_URL>`.
|
LOGIN_URL`` refer to :setting:`settings.LOGIN_URL <LOGIN_URL>`.
|
||||||
|
|
||||||
:setting:`APPEND_SLASH` behaviour has been updated
|
:setting:`APPEND_SLASH` behavior has been updated
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
In 0.96, if a URL didn't end in a slash or have a period in the final
|
In 0.96, if a URL didn't end in a slash or have a period in the final
|
||||||
component of it's path, and ``APPEND_SLASH`` was True, Django would redirect
|
component of its path, and ``APPEND_SLASH`` was True, Django would redirect
|
||||||
to the same URL, but with a slash appended to the end. Now, Django checks to
|
to the same URL, but with a slash appended to the end. Now, Django checks to
|
||||||
see if the pattern without the trailing slash would be matched by something in
|
see whether the pattern without the trailing slash would be matched by
|
||||||
your URL patterns. If so, no redirection takes place, because it is assumed
|
something in your URL patterns. If so, no redirection takes place, because it
|
||||||
you deliberately wanted to catch that pattern.
|
is assumed you deliberately wanted to catch that pattern.
|
||||||
|
|
||||||
For most people, this won't require any changes. Some people, though, have URL
|
For most people, this won't require any changes. Some people, though, have URL
|
||||||
patterns that look like this::
|
patterns that look like this::
|
||||||
|
@ -421,13 +431,13 @@ slash. If you always want a slash on such URLs, rewrite the pattern as::
|
||||||
|
|
||||||
r'/some_prefix/(.*/)$'
|
r'/some_prefix/(.*/)$'
|
||||||
|
|
||||||
Samller model changes
|
Smaller model changes
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
Different exception from ``get()``
|
Different exception from ``get()``
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
The models manager now returns a :exc:`MultipleObjectsReturned` exception
|
Managers now return a :exc:`MultipleObjectsReturned` exception
|
||||||
instead of :exc:`AssertionError`:
|
instead of :exc:`AssertionError`:
|
||||||
|
|
||||||
Old (0.96)::
|
Old (0.96)::
|
||||||
|
@ -482,14 +492,14 @@ New (1.0)::
|
||||||
...
|
...
|
||||||
|
|
||||||
If you forget to make this change, you will see errors about ``FloatField``
|
If you forget to make this change, you will see errors about ``FloatField``
|
||||||
not taking a ``max_digits`` attribute in ``__init__``, since the new
|
not taking a ``max_digits`` attribute in ``__init__``, because the new
|
||||||
``FloatField`` takes no precision-related arguments.
|
``FloatField`` takes no precision-related arguments.
|
||||||
|
|
||||||
If you are using MySQL or PostgreSQL, there are no further changes needed. The
|
If you're using MySQL or PostgreSQL, no further changes are needed. The
|
||||||
database column types for ``DecimalField`` are the same as for the old
|
database column types for ``DecimalField`` are the same as for the old
|
||||||
``FloatField``.
|
``FloatField``.
|
||||||
|
|
||||||
If you are using SQLite, you need to force the database to view the
|
If you're using SQLite, you need to force the database to view the
|
||||||
appropriate columns as decimal types, rather than floats. To do this, you'll
|
appropriate columns as decimal types, rather than floats. To do this, you'll
|
||||||
need to reload your data. Do this after you have made the change to using
|
need to reload your data. Do this after you have made the change to using
|
||||||
``DecimalField`` in your code and updated the Django code.
|
``DecimalField`` in your code and updated the Django code.
|
||||||
|
@ -502,8 +512,8 @@ need to reload your data. Do this after you have made the change to using
|
||||||
database (the name of that file is the ``DATABASE_NAME`` in your settings.py
|
database (the name of that file is the ``DATABASE_NAME`` in your settings.py
|
||||||
file).
|
file).
|
||||||
|
|
||||||
To upgrade each application to use a ``DecimalField``, do the following,
|
To upgrade each application to use a ``DecimalField``, you can do the
|
||||||
replacing ``<app>`` in the code below with each app's name:
|
following, replacing ``<app>`` in the code below with each app's name:
|
||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
|
@ -513,7 +523,7 @@ replacing ``<app>`` in the code below with each app's name:
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
|
|
||||||
1. It is important that you remember to use XML format in the first step of
|
1. It's important that you remember to use XML format in the first step of
|
||||||
this process. We are exploiting a feature of the XML data dumps that makes
|
this process. We are exploiting a feature of the XML data dumps that makes
|
||||||
porting floats to decimals with SQLite possible.
|
porting floats to decimals with SQLite possible.
|
||||||
|
|
||||||
|
@ -544,10 +554,13 @@ some kind (e.g. a button).
|
||||||
``_()`` is no longer in builtins
|
``_()`` is no longer in builtins
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
``_()`` is no longer monkeypatched into builtins. If you were previously
|
``_()`` (the callable object whose name is a single underscore) is no longer
|
||||||
relying on ``_()`` always being present, you should now explicitly import
|
monkeypatched into builtins -- that is, it's no longer available magically in
|
||||||
``ugettext`` or ``ugettext_lazy``, if appropriate, and alias it to ``_``
|
every module.
|
||||||
yourself::
|
|
||||||
|
If you were previously relying on ``_()`` always being present, you should now
|
||||||
|
explicitly import ``ugettext`` or ``ugettext_lazy``, if appropriate, and alias
|
||||||
|
it to ``_`` yourself::
|
||||||
|
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
|
@ -593,9 +606,9 @@ Management commands
|
||||||
Running management commands from your code
|
Running management commands from your code
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
:mod:`django.core.management`` has been greately refactored.
|
:mod:`django.core.management`` has been greatly refactored.
|
||||||
|
|
||||||
Calls to management services in your code will now need to use
|
Calls to management services in your code now need to use
|
||||||
``call_command``. For example, if you have some test code that calls flush and
|
``call_command``. For example, if you have some test code that calls flush and
|
||||||
load_data::
|
load_data::
|
||||||
|
|
||||||
|
@ -603,7 +616,7 @@ load_data::
|
||||||
management.flush(verbosity=0, interactive=False)
|
management.flush(verbosity=0, interactive=False)
|
||||||
management.load_data(['test_data'], verbosity=0)
|
management.load_data(['test_data'], verbosity=0)
|
||||||
|
|
||||||
You will need to change this code to read::
|
...you'll need to change this code to read::
|
||||||
|
|
||||||
from django.core import management
|
from django.core import management
|
||||||
management.call_command('flush', verbosity=0, interactive=False)
|
management.call_command('flush', verbosity=0, interactive=False)
|
||||||
|
@ -619,7 +632,7 @@ options. So:
|
||||||
|
|
||||||
$ django-admin.py --settings=foo.bar runserver
|
$ django-admin.py --settings=foo.bar runserver
|
||||||
|
|
||||||
no longer works, and must be changed to:
|
...no longer works and should be changed to:
|
||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
|
@ -631,7 +644,7 @@ Syndication
|
||||||
``Feed.__init__`` has changed
|
``Feed.__init__`` has changed
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
The ``__init__()`` parameters in in syndication framework's ``Feed`` class now
|
The ``__init__()`` parameters in the syndication framework's ``Feed`` class now
|
||||||
take an ``HttpRequest`` object as its second parameter, instead of the feed's
|
take an ``HttpRequest`` object as its second parameter, instead of the feed's
|
||||||
URL. This allows the syndication framework to work without requiring the sites
|
URL. This allows the syndication framework to work without requiring the sites
|
||||||
framework. This only affects code that subclass ``Feed`` and overrides the
|
framework. This only affects code that subclass ``Feed`` and overrides the
|
||||||
|
@ -652,7 +665,7 @@ To update your code:
|
||||||
1. Use :class:`django.utils.datastructures.SortedDict` wherever you were
|
1. Use :class:`django.utils.datastructures.SortedDict` wherever you were
|
||||||
using ``django.newforms.forms.SortedDictFromList``.
|
using ``django.newforms.forms.SortedDictFromList``.
|
||||||
|
|
||||||
2. Since :meth:`django.utils.datastructures.SortedDict.copy` return a
|
2. Because :meth:`django.utils.datastructures.SortedDict.copy` returns a
|
||||||
deepcopy as ``SortedDictFromList`` method did, you will need to update
|
deepcopy as ``SortedDictFromList`` method did, you will need to update
|
||||||
your code if you were relying on a deepcopy. Do this by using
|
your code if you were relying on a deepcopy. Do this by using
|
||||||
``copy.deepcopy`` directly.
|
``copy.deepcopy`` directly.
|
||||||
|
|
Loading…
Reference in New Issue