升级 Django 到最新的版本

    • New features and improvements are added.
    • bug已经被修复。
    • Older version of Django will eventually no longer receive security updates.(see Supported versions).

    If it's your first time doing an upgrade, it is useful to read the .

    Afterwards, you should familiarize yourself with the changes that were made inthe new Django version(s):

    • Read the release notes for each 'final' release fromthe one after your current Django version, up to and including the version towhich you plan to upgrade.
    • Look at the for therelevant versions.
      Pay particular attention to backwards incompatible changes to get a clear ideaof what will be needed for a successful upgrade.

    If you're upgrading through more than one feature version (e.g. A.B to A.B+2),it's usually easier to upgrade through each feature release incrementally(A.B to A.B+1 to A.B+2) rather than to make all the changes for each featurerelease at once. For each feature release, use the latest patch release (A.B.C).

    The same incremental upgrade approach is recommended when upgrading from oneLTS to the next.

    Dependencies

    Before upgrading, it's a good idea to resolve any deprecation warnings raisedby your project while using your current version of Django. Fixing thesewarnings before upgrading ensures that you're informed about areas of the codethat need altering.

    In Python, deprecation warnings are silenced by default. You must turn them onusing the Python command line option or the environment variable. For example, to show warnings while running tests:

    1. ...\> py -Wa manage.py test

    If you're not using the Django test runner, you may need to also ensure thatany console output is not captured which would hide deprecation warnings. Forexample, if you use py.test:

    Resolve any deprecation warnings with your current version of Django beforecontinuing the upgrade process.

    安装

    Once you're ready, it is time to . If you are using virtualenv and it is a major upgrade, youmight want to set up a new environment with all the dependencies first.

    If you installed Django with , you can use the or -U flag:

    1. $ pip install -U Django

    When the new environment is set up, run the full test suite for your application. Again, it's useful to turnon deprecation warnings on so they're shown in the test output (you can alsouse the flag if you test your app manually using ):

      After you have run the tests, fix any failures. While you have the releasenotes fresh in your mind, it may also be a good time to take advantage of newfeatures in Django by refactoring your code to eliminate any deprecationwarnings.

      Deployment

      If you are using caching provided by Django, you should consider clearing yourcache after upgrading. Otherwise you may run into problems, for example, if youare caching pickled objects as these objects are not guaranteed to bepickle-compatible across Django versions. A past instance of incompatibilitywas caching pickled HttpResponse objects, eitherdirectly or indirectly via the decorator.