{"title":"将你的应用从 Django 0.96 移植到 1.0","version":"3.1","locale":"zh-hans","docname":"releases/1.0-porting-guide","url":"/zh-hans/3.1/releases/1.0-porting-guide/","canonical":"https://djangodocs.dev/zh-hans/3.1/releases/1.0-porting-guide/","summary":"Django 1.0 breaks compatibility with 0.96 in some areas. This guide will help you port 0.96 projects and apps to 1.0. The first part of this document includes the…","html":"<h1>将你的应用从 Django 0.96 移植到 1.0<a class=\"heading-anchor\" href=\"#porting-your-apps-from-django-0-96-to-1-0\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>Django 1.0 breaks compatibility with 0.96 in some areas.</p>\n<p>This guide will help you port 0.96 projects and apps to 1.0. The first part of\nthis document includes the common changes needed to run with 1.0. If after going\nthrough the first part your code still breaks, check the section <a class=\"reference internal\" href=\"#less-common-changes\">Less-common\nChanges</a> for a list of a bunch of less-common compatibility issues.</p>\n<aside class=\"admonition admonition-seealso\">\n<p class=\"admonition-title\">See also</p>\n<p>The <a class=\"reference internal\" href=\"/zh-hans/3.1/releases/1.0/\"><span class=\"doc\">1.0 release notes</span></a>. That document explains the new\nfeatures in 1.0 more deeply; the porting guide is more concerned with\nhelping you quickly update your code.</p>\n</aside>\n<section id=\"common-changes\">\n<h2>Common changes<a class=\"heading-anchor\" href=\"#common-changes\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>This section describes the changes between 0.96 and 1.0 that most users will\nneed to make.</p>\n<section id=\"use-unicode\">\n<h3>Use Unicode<a class=\"heading-anchor\" href=\"#use-unicode\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Change string literals (<code class=\"docutils literal notranslate\"><span class=\"pre\">'foo'</span></code>) into Unicode literals (<code class=\"docutils literal notranslate\"><span class=\"pre\">u'foo'</span></code>). Django\nnow uses Unicode strings throughout. In most places, raw strings will continue\nto work, but updating to use Unicode literals will prevent some obscure\nproblems.</p>\n<p>See <a class=\"reference internal\" href=\"/zh-hans/3.1/ref/unicode/\"><span class=\"doc\">Unicode 数据</span></a> for full details.</p>\n</section>\n<section id=\"models\">\n<h3>模型<a class=\"heading-anchor\" href=\"#models\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Common changes to your models file:</p>\n<section id=\"rename-maxlength-to-max-length\">\n<h4><code class=\"docutils literal notranslate\"><span class=\"pre\">maxlength</span></code> 重命名为 <code class=\"docutils literal notranslate\"><span class=\"pre\">max_length</span></code><a class=\"heading-anchor\" href=\"#rename-maxlength-to-max-length\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Rename your <code class=\"docutils literal notranslate\"><span class=\"pre\">maxlength</span></code> argument to <code class=\"docutils literal notranslate\"><span class=\"pre\">max_length</span></code> (this was changed to be\nconsistent with form fields):</p>\n</section>\n<section id=\"replace-str-with-unicode\">\n<h4>Replace <code class=\"docutils literal notranslate\"><span class=\"pre\">__str__</span></code> with <code class=\"docutils literal notranslate\"><span class=\"pre\">__unicode__</span></code><a class=\"heading-anchor\" href=\"#replace-str-with-unicode\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Replace your model's <code class=\"docutils literal notranslate\"><span class=\"pre\">__str__</span></code> function with a <code class=\"docutils literal notranslate\"><span class=\"pre\">__unicode__</span></code> method, and\nmake sure you <a class=\"reference internal\" href=\"#use-unicode\">use Unicode</a> (<code class=\"docutils literal notranslate\"><span class=\"pre\">u'foo'</span></code>) in that method.</p>\n</section>\n<section id=\"remove-prepopulated-from\">\n<h4>移除 <code class=\"docutils literal notranslate\"><span class=\"pre\">prepopulated_from</span></code><a class=\"heading-anchor\" href=\"#remove-prepopulated-from\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Remove the <code class=\"docutils literal notranslate\"><span class=\"pre\">prepopulated_from</span></code> argument on model fields. It's no longer valid\nand has been moved to the <code class=\"docutils literal notranslate\"><span class=\"pre\">ModelAdmin</span></code> class in <code class=\"docutils literal notranslate\"><span class=\"pre\">admin.py</span></code>. See <a class=\"reference internal\" href=\"#the-admin\">the\nadmin</a>, below, for more details about changes to the admin.</p>\n</section>\n<section id=\"remove-core\">\n<h4>移除 <code class=\"docutils literal notranslate\"><span class=\"pre\">core</span></code><a class=\"heading-anchor\" href=\"#remove-core\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Remove the <code class=\"docutils literal notranslate\"><span class=\"pre\">core</span></code> argument from your model fields. It is no longer\nnecessary, since the equivalent functionality (part of <a class=\"reference internal\" href=\"/zh-hans/3.1/ref/contrib/admin/#admin-inlines\"><span class=\"std std-ref\">inline editing</span></a>) is handled differently by the admin interface now. You don't\nhave to worry about inline editing until you get to <a class=\"reference internal\" href=\"#the-admin\">the admin</a> section,\nbelow. For now, remove all references to <code class=\"docutils literal notranslate\"><span class=\"pre\">core</span></code>.</p>\n</section>\n<section id=\"replace-class-admin-with-admin-py\">\n<h4>用 <code class=\"docutils literal notranslate\"><span class=\"pre\">admin.py</span></code> 替换  <code class=\"docutils literal notranslate\"><span class=\"pre\">class</span> <span class=\"pre\">Admin:</span></code><a class=\"heading-anchor\" href=\"#replace-class-admin-with-admin-py\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Remove all your inner <code class=\"docutils literal notranslate\"><span class=\"pre\">class</span> <span class=\"pre\">Admin</span></code> declarations from your models. They won't\nbreak anything if you leave them, but they also won't do anything. To register\napps with the admin you'll move those declarations to an <code class=\"docutils literal notranslate\"><span class=\"pre\">admin.py</span></code> file;\nsee <a class=\"reference internal\" href=\"#the-admin\">the admin</a> below for more details.</p>\n<aside class=\"admonition admonition-seealso\">\n<p class=\"admonition-title\">See also</p>\n<p>A contributor to <a class=\"reference external\" href=\"https://www.djangosnippets.org/\">djangosnippets</a> has written a script that'll <a class=\"reference external\" href=\"https://www.djangosnippets.org/snippets/603/\">scan your\nmodels.py and generate a corresponding admin.py</a>.</p>\n</aside>\n</section>\n<section id=\"example\">\n<h4>例如<a class=\"heading-anchor\" href=\"#example\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Below is an example <code class=\"docutils literal notranslate\"><span class=\"pre\">models.py</span></code> file with all the changes you'll need to make:</p>\n<p>Old (0.96) <code class=\"docutils literal notranslate\"><span class=\"pre\">models.py</span></code>:</p>\n<div class=\"code-block\" data-language=\"python\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">Author</span><span class=\"p\">(</span><span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">Model</span><span class=\"p\">):</span>\n    <span class=\"n\">first_name</span> <span class=\"o\">=</span> <span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">CharField</span><span class=\"p\">(</span><span class=\"n\">maxlength</span><span class=\"o\">=</span><span class=\"mi\">30</span><span class=\"p\">)</span>\n    <span class=\"n\">last_name</span> <span class=\"o\">=</span> <span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">CharField</span><span class=\"p\">(</span><span class=\"n\">maxlength</span><span class=\"o\">=</span><span class=\"mi\">30</span><span class=\"p\">)</span>\n    <span class=\"n\">slug</span> <span class=\"o\">=</span> <span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">CharField</span><span class=\"p\">(</span><span class=\"n\">maxlength</span><span class=\"o\">=</span><span class=\"mi\">60</span><span class=\"p\">,</span> <span class=\"n\">prepopulate_from</span><span class=\"o\">=</span><span class=\"p\">(</span><span class=\"s1\">&#39;first_name&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;last_name&#39;</span><span class=\"p\">))</span>\n\n    <span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">Admin</span><span class=\"p\">:</span>\n        <span class=\"n\">list_display</span> <span class=\"o\">=</span> <span class=\"p\">[</span><span class=\"s1\">&#39;first_name&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;last_name&#39;</span><span class=\"p\">]</span>\n\n    <span class=\"k\">def</span><span class=\"w\"> </span><span class=\"fm\">__str__</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n        <span class=\"k\">return</span> <span class=\"s1\">&#39;</span><span class=\"si\">%s</span><span class=\"s1\"> </span><span class=\"si\">%s</span><span class=\"s1\">&#39;</span> <span class=\"o\">%</span> <span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">first_name</span><span class=\"p\">,</span> <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">last_name</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>New (1.0) <code class=\"docutils literal notranslate\"><span class=\"pre\">models.py</span></code>:</p>\n<div class=\"code-block\" data-language=\"python\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">Author</span><span class=\"p\">(</span><span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">Model</span><span class=\"p\">):</span>\n    <span class=\"n\">first_name</span> <span class=\"o\">=</span> <span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">CharField</span><span class=\"p\">(</span><span class=\"n\">max_length</span><span class=\"o\">=</span><span class=\"mi\">30</span><span class=\"p\">)</span>\n    <span class=\"n\">last_name</span> <span class=\"o\">=</span> <span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">CharField</span><span class=\"p\">(</span><span class=\"n\">max_length</span><span class=\"o\">=</span><span class=\"mi\">30</span><span class=\"p\">)</span>\n    <span class=\"n\">slug</span> <span class=\"o\">=</span> <span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">CharField</span><span class=\"p\">(</span><span class=\"n\">max_length</span><span class=\"o\">=</span><span class=\"mi\">60</span><span class=\"p\">)</span>\n\n    <span class=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">__unicode__</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n        <span class=\"k\">return</span> <span class=\"sa\">u</span><span class=\"s1\">&#39;</span><span class=\"si\">%s</span><span class=\"s1\"> </span><span class=\"si\">%s</span><span class=\"s1\">&#39;</span> <span class=\"o\">%</span> <span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">first_name</span><span class=\"p\">,</span> <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">last_name</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>New (1.0) <code class=\"docutils literal notranslate\"><span class=\"pre\">admin.py</span></code>:</p>\n<div class=\"code-block\" data-language=\"python\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.contrib</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">admin</span>\n<span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">models</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">Author</span>\n\n<span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">AuthorAdmin</span><span class=\"p\">(</span><span class=\"n\">admin</span><span class=\"o\">.</span><span class=\"n\">ModelAdmin</span><span class=\"p\">):</span>\n    <span class=\"n\">list_display</span> <span class=\"o\">=</span> <span class=\"p\">[</span><span class=\"s1\">&#39;first_name&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;last_name&#39;</span><span class=\"p\">]</span>\n    <span class=\"n\">prepopulated_fields</span> <span class=\"o\">=</span> <span class=\"p\">{</span>\n        <span class=\"s1\">&#39;slug&#39;</span><span class=\"p\">:</span> <span class=\"p\">(</span><span class=\"s1\">&#39;first_name&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;last_name&#39;</span><span class=\"p\">)</span>\n    <span class=\"p\">}</span>\n\n<span class=\"n\">admin</span><span class=\"o\">.</span><span class=\"n\">site</span><span class=\"o\">.</span><span class=\"n\">register</span><span class=\"p\">(</span><span class=\"n\">Author</span><span class=\"p\">,</span> <span class=\"n\">AuthorAdmin</span><span class=\"p\">)</span>\n</code></pre></div>\n</section>\n</section>\n<section id=\"the-admin\">\n<h3>The Admin<a class=\"heading-anchor\" href=\"#the-admin\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>One of the biggest changes in 1.0 is the new admin. The Django administrative\ninterface (<code class=\"docutils literal notranslate\"><span class=\"pre\">django.contrib.admin</span></code>) has been completely refactored; admin\ndefinitions are now completely decoupled from model definitions, the framework\nhas been rewritten to use Django's new form-handling library and redesigned with\nextensibility and customization in mind.</p>\n<p>Practically, this means you'll need to rewrite all of your <code class=\"docutils literal notranslate\"><span class=\"pre\">class</span> <span class=\"pre\">Admin</span></code>\ndeclarations. You've already seen in <a class=\"reference internal\" href=\"#models\">models</a> above how to replace your <code class=\"docutils literal notranslate\"><span class=\"pre\">class</span>\n<span class=\"pre\">Admin</span></code> with an <code class=\"docutils literal notranslate\"><span class=\"pre\">admin.site.register()</span></code> call in an <code class=\"docutils literal notranslate\"><span class=\"pre\">admin.py</span></code> file. Below are\nsome more details on how to rewrite that <code class=\"docutils literal notranslate\"><span class=\"pre\">Admin</span></code> declaration into the new\nsyntax.</p>\n<section id=\"use-new-inline-syntax\">\n<h4>Use new inline syntax<a class=\"heading-anchor\" href=\"#use-new-inline-syntax\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>The new <code class=\"docutils literal notranslate\"><span class=\"pre\">edit_inline</span></code> options have all been moved to <code class=\"docutils literal notranslate\"><span class=\"pre\">admin.py</span></code>. Here's an\nexample:</p>\n<p>Old (0.96):</p>\n<div class=\"code-block\" data-language=\"python\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">Parent</span><span class=\"p\">(</span><span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">Model</span><span class=\"p\">):</span>\n    <span class=\"o\">...</span>\n\n<span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">Child</span><span class=\"p\">(</span><span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">Model</span><span class=\"p\">):</span>\n    <span class=\"n\">parent</span> <span class=\"o\">=</span> <span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">ForeignKey</span><span class=\"p\">(</span><span class=\"n\">Parent</span><span class=\"p\">,</span> <span class=\"n\">edit_inline</span><span class=\"o\">=</span><span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">STACKED</span><span class=\"p\">,</span> <span class=\"n\">num_in_admin</span><span class=\"o\">=</span><span class=\"mi\">3</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>New (1.0):</p>\n<div class=\"code-block\" data-language=\"python\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">ChildInline</span><span class=\"p\">(</span><span class=\"n\">admin</span><span class=\"o\">.</span><span class=\"n\">StackedInline</span><span class=\"p\">):</span>\n    <span class=\"n\">model</span> <span class=\"o\">=</span> <span class=\"n\">Child</span>\n    <span class=\"n\">extra</span> <span class=\"o\">=</span> <span class=\"mi\">3</span>\n\n<span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">ParentAdmin</span><span class=\"p\">(</span><span class=\"n\">admin</span><span class=\"o\">.</span><span class=\"n\">ModelAdmin</span><span class=\"p\">):</span>\n    <span class=\"n\">model</span> <span class=\"o\">=</span> <span class=\"n\">Parent</span>\n    <span class=\"n\">inlines</span> <span class=\"o\">=</span> <span class=\"p\">[</span><span class=\"n\">ChildInline</span><span class=\"p\">]</span>\n\n<span class=\"n\">admin</span><span class=\"o\">.</span><span class=\"n\">site</span><span class=\"o\">.</span><span class=\"n\">register</span><span class=\"p\">(</span><span class=\"n\">Parent</span><span class=\"p\">,</span> <span class=\"n\">ParentAdmin</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>See <a class=\"reference internal\" href=\"/zh-hans/3.1/ref/contrib/admin/#admin-inlines\"><span class=\"std std-ref\">InlineModelAdmin 对象</span></a> for more details.</p>\n</section>\n<section id=\"simplify-fields-or-use-fieldsets\">\n<h4>Simplify <code class=\"docutils literal notranslate\"><span class=\"pre\">fields</span></code>, or use <code class=\"docutils literal notranslate\"><span class=\"pre\">fieldsets</span></code><a class=\"heading-anchor\" href=\"#simplify-fields-or-use-fieldsets\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>The old <code class=\"docutils literal notranslate\"><span class=\"pre\">fields</span></code> syntax was quite confusing, and has been simplified. The old\nsyntax still works, but you'll need to use <code class=\"docutils literal notranslate\"><span class=\"pre\">fieldsets</span></code> instead.</p>\n<p>Old (0.96):</p>\n<div class=\"code-block\" data-language=\"python\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">ModelOne</span><span class=\"p\">(</span><span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">Model</span><span class=\"p\">):</span>\n    <span class=\"o\">...</span>\n\n    <span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">Admin</span><span class=\"p\">:</span>\n        <span class=\"n\">fields</span> <span class=\"o\">=</span> <span class=\"p\">(</span>\n            <span class=\"p\">(</span><span class=\"kc\">None</span><span class=\"p\">,</span> <span class=\"p\">{</span><span class=\"s1\">&#39;fields&#39;</span><span class=\"p\">:</span> <span class=\"p\">(</span><span class=\"s1\">&#39;foo&#39;</span><span class=\"p\">,</span><span class=\"s1\">&#39;bar&#39;</span><span class=\"p\">)}),</span>\n        <span class=\"p\">)</span>\n\n<span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">ModelTwo</span><span class=\"p\">(</span><span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">Model</span><span class=\"p\">):</span>\n    <span class=\"o\">...</span>\n\n    <span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">Admin</span><span class=\"p\">:</span>\n        <span class=\"n\">fields</span> <span class=\"o\">=</span> <span class=\"p\">(</span>\n            <span class=\"p\">(</span><span class=\"s1\">&#39;group1&#39;</span><span class=\"p\">,</span> <span class=\"p\">{</span><span class=\"s1\">&#39;fields&#39;</span><span class=\"p\">:</span> <span class=\"p\">(</span><span class=\"s1\">&#39;foo&#39;</span><span class=\"p\">,</span><span class=\"s1\">&#39;bar&#39;</span><span class=\"p\">),</span>   <span class=\"s1\">&#39;classes&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;collapse&#39;</span><span class=\"p\">}),</span>\n            <span class=\"p\">(</span><span class=\"s1\">&#39;group2&#39;</span><span class=\"p\">,</span> <span class=\"p\">{</span><span class=\"s1\">&#39;fields&#39;</span><span class=\"p\">:</span> <span class=\"p\">(</span><span class=\"s1\">&#39;spam&#39;</span><span class=\"p\">,</span><span class=\"s1\">&#39;eggs&#39;</span><span class=\"p\">),</span> <span class=\"s1\">&#39;classes&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;collapse wide&#39;</span><span class=\"p\">}),</span>\n        <span class=\"p\">)</span>\n</code></pre></div>\n<p>New (1.0):</p>\n<div class=\"code-block\" data-language=\"python\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">ModelOneAdmin</span><span class=\"p\">(</span><span class=\"n\">admin</span><span class=\"o\">.</span><span class=\"n\">ModelAdmin</span><span class=\"p\">):</span>\n    <span class=\"n\">fields</span> <span class=\"o\">=</span> <span class=\"p\">(</span><span class=\"s1\">&#39;foo&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;bar&#39;</span><span class=\"p\">)</span>\n\n<span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">ModelTwoAdmin</span><span class=\"p\">(</span><span class=\"n\">admin</span><span class=\"o\">.</span><span class=\"n\">ModelAdmin</span><span class=\"p\">):</span>\n    <span class=\"n\">fieldsets</span> <span class=\"o\">=</span> <span class=\"p\">(</span>\n        <span class=\"p\">(</span><span class=\"s1\">&#39;group1&#39;</span><span class=\"p\">,</span> <span class=\"p\">{</span><span class=\"s1\">&#39;fields&#39;</span><span class=\"p\">:</span> <span class=\"p\">(</span><span class=\"s1\">&#39;foo&#39;</span><span class=\"p\">,</span><span class=\"s1\">&#39;bar&#39;</span><span class=\"p\">),</span>   <span class=\"s1\">&#39;classes&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;collapse&#39;</span><span class=\"p\">}),</span>\n        <span class=\"p\">(</span><span class=\"s1\">&#39;group2&#39;</span><span class=\"p\">,</span> <span class=\"p\">{</span><span class=\"s1\">&#39;fields&#39;</span><span class=\"p\">:</span> <span class=\"p\">(</span><span class=\"s1\">&#39;spam&#39;</span><span class=\"p\">,</span><span class=\"s1\">&#39;eggs&#39;</span><span class=\"p\">),</span> <span class=\"s1\">&#39;classes&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;collapse wide&#39;</span><span class=\"p\">}),</span>\n    <span class=\"p\">)</span>\n</code></pre></div>\n<aside class=\"admonition admonition-seealso\">\n<p class=\"admonition-title\">See also</p>\n<ul class=\"simple\">\n<li><p>More detailed information about the changes and the reasons behind them\ncan be found on the <a class=\"reference external\" href=\"https://code.djangoproject.com/wiki/NewformsAdminBranch\">NewformsAdminBranch wiki page</a></p></li>\n<li><p>The new admin comes with a ton of new features; you can read about them in\nthe <a class=\"reference internal\" href=\"/zh-hans/3.1/ref/contrib/admin/\"><span class=\"doc\">admin documentation</span></a>.</p></li>\n</ul>\n</aside>\n</section>\n</section>\n<section id=\"urls\">\n<h3>URLs<a class=\"heading-anchor\" href=\"#urls\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<section id=\"update-your-root-urls-py\">\n<h4>Update your root <code class=\"docutils literal notranslate\"><span class=\"pre\">urls.py</span></code><a class=\"heading-anchor\" href=\"#update-your-root-urls-py\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>If you're using the admin site, you need to update your root <code class=\"docutils literal notranslate\"><span class=\"pre\">urls.py</span></code>.</p>\n<p>Old (0.96) <code class=\"docutils literal notranslate\"><span class=\"pre\">urls.py</span></code>:</p>\n<div class=\"code-block\" data-language=\"python\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.conf.urls.defaults</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"o\">*</span>\n\n<span class=\"n\">urlpatterns</span> <span class=\"o\">=</span> <span class=\"n\">patterns</span><span class=\"p\">(</span><span class=\"s1\">&#39;&#39;</span><span class=\"p\">,</span>\n    <span class=\"p\">(</span><span class=\"sa\">r</span><span class=\"s1\">&#39;^admin/&#39;</span><span class=\"p\">,</span> <span class=\"n\">include</span><span class=\"p\">(</span><span class=\"s1\">&#39;django.contrib.admin.urls&#39;</span><span class=\"p\">)),</span>\n\n    <span class=\"c1\"># ... the rest of your URLs here ...</span>\n<span class=\"p\">)</span>\n</code></pre></div>\n<p>New (1.0) <code class=\"docutils literal notranslate\"><span class=\"pre\">urls.py</span></code>:</p>\n<div class=\"code-block\" data-language=\"python\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.conf.urls.defaults</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"o\">*</span>\n\n<span class=\"c1\"># The next two lines enable the admin and load each admin.py file:</span>\n<span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.contrib</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">admin</span>\n<span class=\"n\">admin</span><span class=\"o\">.</span><span class=\"n\">autodiscover</span><span class=\"p\">()</span>\n\n<span class=\"n\">urlpatterns</span> <span class=\"o\">=</span> <span class=\"n\">patterns</span><span class=\"p\">(</span><span class=\"s1\">&#39;&#39;</span><span class=\"p\">,</span>\n    <span class=\"p\">(</span><span class=\"sa\">r</span><span class=\"s1\">&#39;^admin/(.*)&#39;</span><span class=\"p\">,</span> <span class=\"n\">admin</span><span class=\"o\">.</span><span class=\"n\">site</span><span class=\"o\">.</span><span class=\"n\">root</span><span class=\"p\">),</span>\n\n    <span class=\"c1\"># ... the rest of your URLs here ...</span>\n<span class=\"p\">)</span>\n</code></pre></div>\n</section>\n</section>\n<section id=\"views\">\n<h3>视图<a class=\"heading-anchor\" href=\"#views\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<section id=\"use-django-forms-instead-of-newforms\">\n<h4>Use <code class=\"docutils literal notranslate\"><span class=\"pre\">django.forms</span></code> instead of <code class=\"docutils literal notranslate\"><span class=\"pre\">newforms</span></code><a class=\"heading-anchor\" href=\"#use-django-forms-instead-of-newforms\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Replace <code class=\"docutils literal notranslate\"><span class=\"pre\">django.newforms</span></code> with <code class=\"docutils literal notranslate\"><span class=\"pre\">django.forms</span></code> -- Django 1.0 renamed the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">newforms</span></code> module (introduced in 0.96) to plain old <code class=\"docutils literal notranslate\"><span class=\"pre\">forms</span></code>. The\n<code class=\"docutils literal notranslate\"><span class=\"pre\">oldforms</span></code> module was also removed.</p>\n<p>If you're already using the <code class=\"docutils literal notranslate\"><span class=\"pre\">newforms</span></code> library, and you used our recommended\n<code class=\"docutils literal notranslate\"><span class=\"pre\">import</span></code> statement syntax, all you have to do is change your import\nstatements.</p>\n<p>Old:</p>\n<div class=\"code-block\" data-language=\"python\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">newforms</span> <span class=\"k\">as</span> <span class=\"n\">forms</span>\n</code></pre></div>\n<p>New:</p>\n<div class=\"code-block\" data-language=\"python\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">forms</span>\n</code></pre></div>\n<p>If you're using the old forms system (formerly known as <code class=\"docutils literal notranslate\"><span class=\"pre\">django.forms</span></code> and\n<code class=\"docutils literal notranslate\"><span class=\"pre\">django.oldforms</span></code>), you'll have to rewrite your forms. A good place to start\nis the <a class=\"reference internal\" href=\"/zh-hans/3.1/topics/forms/\"><span class=\"doc\">forms documentation</span></a></p>\n</section>\n<section id=\"handle-uploaded-files-using-the-new-api\">\n<h4>Handle uploaded files using the new API<a class=\"heading-anchor\" href=\"#handle-uploaded-files-using-the-new-api\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Replace use of uploaded files -- that is, entries in <code class=\"docutils literal notranslate\"><span class=\"pre\">request.FILES</span></code> -- as\nsimple dictionaries with the new\n<a class=\"reference internal\" href=\"/zh-hans/3.1/ref/files/uploads/#django.core.files.uploadedfile.UploadedFile\" title=\"django.core.files.uploadedfile.UploadedFile\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">UploadedFile</span></code></a>. The old dictionary\nsyntax no longer works.</p>\n<p>Thus, in a view like:</p>\n<div class=\"code-block\" data-language=\"python\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"k\">def</span><span class=\"w\"> </span><span class=\"nf\">my_view</span><span class=\"p\">(</span><span class=\"n\">request</span><span class=\"p\">):</span>\n    <span class=\"n\">f</span> <span class=\"o\">=</span> <span class=\"n\">request</span><span class=\"o\">.</span><span class=\"n\">FILES</span><span class=\"p\">[</span><span class=\"s1\">&#39;file_field_name&#39;</span><span class=\"p\">]</span>\n    <span class=\"o\">...</span>\n</code></pre></div>\n<p>...you'd need to make the following changes:</p>\n<div class=\"table-scroll\" role=\"region\" tabindex=\"0\" aria-label=\"Table\"><table class=\"docutils align-default\">\n<thead>\n<tr class=\"row-odd\"><th class=\"head\"><p>Old (0.96)</p></th>\n<th class=\"head\"><p>New (1.0)</p></th>\n</tr>\n</thead>\n<tbody>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">f['content']</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">f.read()</span></code></p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">f['filename']</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">f.name</span></code></p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">f['content-type']</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">f.content_type</span></code></p></td>\n</tr>\n</tbody>\n</table>\n</div>\n</section>\n<section id=\"work-with-file-fields-using-the-new-api\">\n<h4>Work with file fields using the new API<a class=\"heading-anchor\" href=\"#work-with-file-fields-using-the-new-api\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>The internal implementation of <a class=\"reference internal\" href=\"/zh-hans/3.1/ref/models/fields/#django.db.models.FileField\" title=\"django.db.models.FileField\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">django.db.models.FileField</span></code></a> have changed.\nA visible result of this is that the way you access special attributes (URL,\nfilename, image size, etc.) of these model fields has changed. You will need to\nmake the following changes, assuming your model's\n<a class=\"reference internal\" href=\"/zh-hans/3.1/ref/models/fields/#django.db.models.FileField\" title=\"django.db.models.FileField\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">FileField</span></code></a> is called <code class=\"docutils literal notranslate\"><span class=\"pre\">myfile</span></code>:</p>\n<div class=\"table-scroll\" role=\"region\" tabindex=\"0\" aria-label=\"Table\"><table class=\"docutils align-default\">\n<thead>\n<tr class=\"row-odd\"><th class=\"head\"><p>Old (0.96)</p></th>\n<th class=\"head\"><p>New (1.0)</p></th>\n</tr>\n</thead>\n<tbody>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">myfile.get_content_filename()</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">myfile.content.path</span></code></p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">myfile.get_content_url()</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">myfile.content.url</span></code></p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">myfile.get_content_size()</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">myfile.content.size</span></code></p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">myfile.save_content_file()</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">myfile.content.save()</span></code></p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">myfile.get_content_width()</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">myfile.content.width</span></code></p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">myfile.get_content_height()</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">myfile.content.height</span></code></p></td>\n</tr>\n</tbody>\n</table>\n</div>\n<p>Note that the <code class=\"docutils literal notranslate\"><span class=\"pre\">width</span></code> and <code class=\"docutils literal notranslate\"><span class=\"pre\">height</span></code> attributes only make sense for\n<a class=\"reference internal\" href=\"/zh-hans/3.1/ref/models/fields/#django.db.models.ImageField\" title=\"django.db.models.ImageField\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">ImageField</span></code></a> fields. More details can be found in the\n<a class=\"reference internal\" href=\"/zh-hans/3.1/ref/models/fields/\"><span class=\"doc\">model API</span></a> documentation.</p>\n</section>\n<section id=\"use-paginator-instead-of-objectpaginator\">\n<h4>Use <code class=\"docutils literal notranslate\"><span class=\"pre\">Paginator</span></code> instead of <code class=\"docutils literal notranslate\"><span class=\"pre\">ObjectPaginator</span></code><a class=\"heading-anchor\" href=\"#use-paginator-instead-of-objectpaginator\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>The <code class=\"docutils literal notranslate\"><span class=\"pre\">ObjectPaginator</span></code> in 0.96 has been removed and replaced with an improved\nversion, <a class=\"reference internal\" href=\"/zh-hans/3.1/ref/paginator/#django.core.paginator.Paginator\" title=\"django.core.paginator.Paginator\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">django.core.paginator.Paginator</span></code></a>.</p>\n</section>\n</section>\n<section id=\"templates\">\n<h3>模板<a class=\"heading-anchor\" href=\"#templates\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<section id=\"learn-to-love-autoescaping\">\n<h4>Learn to love autoescaping<a class=\"heading-anchor\" href=\"#learn-to-love-autoescaping\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>By default, the template system now automatically HTML-escapes the output of\nevery variable. To learn more, see <a class=\"reference internal\" href=\"/zh-hans/3.1/ref/templates/language/#automatic-html-escaping\"><span class=\"std std-ref\">自动 HTML 转义</span></a>.</p>\n<p>To disable auto-escaping for an individual variable, use the <a class=\"reference internal\" href=\"/zh-hans/3.1/ref/templates/builtins/#std-templatefilter-safe\"><code class=\"xref std std-tfilter docutils literal notranslate\"><span class=\"pre\">safe</span></code></a>\nfilter:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Django template code\"><code>This will be escaped: <span class=\"cp\">{{</span> <span class=\"nv\">data</span> <span class=\"cp\">}}</span>\nThis will not be escaped: <span class=\"cp\">{{</span> <span class=\"nv\">data</span><span class=\"o\">|</span><span class=\"nf\">safe</span> <span class=\"cp\">}}</span>\n</code></pre></div>\n<p>To disable auto-escaping for an entire template, wrap the template (or just a\nparticular section of the template) in the <a class=\"reference internal\" href=\"/zh-hans/3.1/ref/templates/builtins/#std-templatetag-autoescape\"><code class=\"xref std std-ttag docutils literal notranslate\"><span class=\"pre\">autoescape</span></code></a> tag:</p>\n<div class=\"code-block\" data-language=\"html+django\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Django template</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Django template code\"><code><span class=\"cp\">{%</span> <span class=\"k\">autoescape</span> <span class=\"nv\">off</span> <span class=\"cp\">%}</span>\n   ... unescaped template content here ...\n<span class=\"cp\">{%</span> <span class=\"k\">endautoescape</span> <span class=\"cp\">%}</span>\n</code></pre></div>\n</section>\n</section>\n</section>\n<section id=\"less-common-changes\">\n<h2>Less-common changes<a class=\"heading-anchor\" href=\"#less-common-changes\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>The following changes are smaller, more localized changes. They should only\naffect more advanced users, but it's probably worth reading through the list and\nchecking your code for these things.</p>\n<section id=\"signals\">\n<h3>信号<a class=\"heading-anchor\" href=\"#signals\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<ul class=\"simple\">\n<li><p>Add <code class=\"docutils literal notranslate\"><span class=\"pre\">**kwargs</span></code> to any registered signal handlers.</p></li>\n<li><p>Connect, disconnect, and send signals via methods on the\n<a class=\"reference internal\" href=\"/zh-hans/3.1/topics/signals/#django.dispatch.Signal\" title=\"django.dispatch.Signal\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">Signal</span></code></a> object instead of through module methods in\n<code class=\"docutils literal notranslate\"><span class=\"pre\">django.dispatch.dispatcher</span></code>.</p></li>\n<li><p>Remove any use of the <code class=\"docutils literal notranslate\"><span class=\"pre\">Anonymous</span></code> and <code class=\"docutils literal notranslate\"><span class=\"pre\">Any</span></code> sender options; they no longer\nexist. You can still receive signals sent by any sender by using\n<code class=\"docutils literal notranslate\"><span class=\"pre\">sender=None</span></code></p></li>\n<li><p>Make any custom signals you've declared into instances of\n<a class=\"reference internal\" href=\"/zh-hans/3.1/topics/signals/#django.dispatch.Signal\" title=\"django.dispatch.Signal\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">django.dispatch.Signal</span></code></a> instead of anonymous objects.</p></li>\n</ul>\n<p>Here's quick summary of the code changes you'll need to make:</p>\n<div class=\"table-scroll\" role=\"region\" tabindex=\"0\" aria-label=\"Table\"><table class=\"docutils align-default\">\n<thead>\n<tr class=\"row-odd\"><th class=\"head\"><p>Old (0.96)</p></th>\n<th class=\"head\"><p>New (1.0)</p></th>\n</tr>\n</thead>\n<tbody>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">def</span> <span class=\"pre\">callback(sender)</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">def</span> <span class=\"pre\">callback(sender,</span> <span class=\"pre\">**kwargs)</span></code></p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">sig</span> <span class=\"pre\">=</span> <span class=\"pre\">object()</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">sig</span> <span class=\"pre\">=</span> <span class=\"pre\">django.dispatch.Signal()</span></code></p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">dispatcher.connect(callback,</span> <span class=\"pre\">sig)</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">sig.connect(callback)</span></code></p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">dispatcher.send(sig,</span> <span class=\"pre\">sender)</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">sig.send(sender)</span></code></p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">dispatcher.connect(callback,</span> <span class=\"pre\">sig,</span> <span class=\"pre\">sender=Any)</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">sig.connect(callback,</span> <span class=\"pre\">sender=None)</span></code></p></td>\n</tr>\n</tbody>\n</table>\n</div>\n</section>\n<section id=\"comments\">\n<h3>评论<a class=\"heading-anchor\" href=\"#comments\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>If you were using Django 0.96's <code class=\"docutils literal notranslate\"><span class=\"pre\">django.contrib.comments</span></code> app, you'll need to\nupgrade to the new comments app introduced in 1.0. See the upgrade guide\nfor details.</p>\n</section>\n<section id=\"template-tags\">\n<h3>模板标签<a class=\"heading-anchor\" href=\"#template-tags\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<section id=\"spaceless-tag\">\n<h4><a class=\"reference internal\" href=\"/zh-hans/3.1/ref/templates/builtins/#std-templatetag-spaceless\"><code class=\"xref std std-ttag docutils literal notranslate\"><span class=\"pre\">spaceless</span></code></a> tag<a class=\"heading-anchor\" href=\"#spaceless-tag\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>The <code class=\"docutils literal notranslate\"><span class=\"pre\">spaceless</span></code> template tag now removes <em>all</em> spaces between HTML tags,\ninstead of preserving a single space.</p>\n</section>\n</section>\n<section id=\"local-flavors\">\n<h3>Local flavors<a class=\"heading-anchor\" href=\"#local-flavors\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<section id=\"u-s-local-flavor\">\n<h4>U.S. local flavor<a class=\"heading-anchor\" href=\"#u-s-local-flavor\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">django.contrib.localflavor.usa</span></code> has been renamed to\n<code class=\"docutils literal notranslate\"><span class=\"pre\">django.contrib.localflavor.us</span></code>. This change was made to match the naming\nscheme of other local flavors. To migrate your code, all you need to do is\nchange the imports.</p>\n</section>\n</section>\n<section id=\"sessions\">\n<h3>会话<a class=\"heading-anchor\" href=\"#sessions\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<section id=\"getting-a-new-session-key\">\n<h4>Getting a new session key<a class=\"heading-anchor\" href=\"#getting-a-new-session-key\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">SessionBase.get_new_session_key()</span></code> has been renamed to\n<code class=\"docutils literal notranslate\"><span class=\"pre\">_get_new_session_key()</span></code>. <code class=\"docutils literal notranslate\"><span class=\"pre\">get_new_session_object()</span></code> no longer exists.</p>\n</section>\n</section>\n<section id=\"fixtures\">\n<h3>辅助工具<a class=\"heading-anchor\" href=\"#fixtures\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<section id=\"loading-a-row-no-longer-calls-save\">\n<h4>Loading a row no longer calls <code class=\"docutils literal notranslate\"><span class=\"pre\">save()</span></code><a class=\"heading-anchor\" href=\"#loading-a-row-no-longer-calls-save\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Previously, loading a row automatically ran the model's <code class=\"docutils literal notranslate\"><span class=\"pre\">save()</span></code> method. This\nis no longer the case, so any fields (for example: timestamps) that were\nauto-populated by a <code class=\"docutils literal notranslate\"><span class=\"pre\">save()</span></code> now need explicit values in any fixture.</p>\n</section>\n</section>\n<section id=\"settings\">\n<h3>配置<a class=\"heading-anchor\" href=\"#settings\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<section id=\"better-exceptions\">\n<h4>Better exceptions<a class=\"heading-anchor\" href=\"#better-exceptions\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>The old <a class=\"reference external\" href=\"https://docs.python.org/3/library/exceptions.html#EnvironmentError\" title=\"(in Python v3.14)\"><code class=\"xref py py-exc docutils literal notranslate\"><span class=\"pre\">EnvironmentError</span></code></a> has split into an\n<a class=\"reference external\" href=\"https://docs.python.org/3/library/exceptions.html#ImportError\" title=\"(in Python v3.14)\"><code class=\"xref py py-exc docutils literal notranslate\"><span class=\"pre\">ImportError</span></code></a> when Django fails to find the settings module\nand a <a class=\"reference external\" href=\"https://docs.python.org/3/library/exceptions.html#RuntimeError\" title=\"(in Python v3.14)\"><code class=\"xref py py-exc docutils literal notranslate\"><span class=\"pre\">RuntimeError</span></code></a> when you try to reconfigure settings\nafter having already used them.</p>\n</section>\n<section id=\"login-url-has-moved\">\n<h4><a class=\"reference internal\" href=\"/zh-hans/3.1/ref/settings/#std-setting-LOGIN_URL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LOGIN_URL</span></code></a> has moved<a class=\"heading-anchor\" href=\"#login-url-has-moved\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>The <a class=\"reference internal\" href=\"/zh-hans/3.1/ref/settings/#std-setting-LOGIN_URL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">LOGIN_URL</span></code></a> constant moved from <code class=\"docutils literal notranslate\"><span class=\"pre\">django.contrib.auth</span></code> into the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">settings</span></code> module. Instead of using <code class=\"docutils literal notranslate\"><span class=\"pre\">from</span> <span class=\"pre\">django.contrib.auth</span> <span class=\"pre\">import</span>\n<span class=\"pre\">LOGIN_URL</span></code> refer to <a class=\"reference internal\" href=\"/zh-hans/3.1/ref/settings/#std-setting-LOGIN_URL\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">settings.LOGIN_URL</span></code></a>.</p>\n</section>\n<section id=\"append-slash-behavior-has-been-updated\">\n<h4><a class=\"reference internal\" href=\"/zh-hans/3.1/ref/settings/#std-setting-APPEND_SLASH\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">APPEND_SLASH</span></code></a> behavior has been updated<a class=\"heading-anchor\" href=\"#append-slash-behavior-has-been-updated\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>In 0.96, if a URL didn't end in a slash or have a period in the final\ncomponent of its path, and <a class=\"reference internal\" href=\"/zh-hans/3.1/ref/settings/#std-setting-APPEND_SLASH\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">APPEND_SLASH</span></code></a> was True, Django would\nredirect to the same URL, but with a slash appended to the end. Now, Django\nchecks to see whether the pattern without the trailing slash would be matched\nby something in your URL patterns. If so, no redirection takes place, because\nit is assumed you deliberately wanted to catch that pattern.</p>\n<p>For most people, this won't require any changes. Some people, though, have URL\npatterns that look like this:</p>\n<div class=\"code-block\" data-language=\"python\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"sa\">r</span><span class=\"s1\">&#39;/some_prefix/(.*)$&#39;</span>\n</code></pre></div>\n<p>Previously, those patterns would have been redirected to have a trailing\nslash. If you always want a slash on such URLs, rewrite the pattern as:</p>\n<div class=\"code-block\" data-language=\"python\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"sa\">r</span><span class=\"s1\">&#39;/some_prefix/(.*/)$&#39;</span>\n</code></pre></div>\n</section>\n</section>\n<section id=\"smaller-model-changes\">\n<h3>Smaller model changes<a class=\"heading-anchor\" href=\"#smaller-model-changes\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<section id=\"different-exception-from-get\">\n<h4>Different exception from <code class=\"docutils literal notranslate\"><span class=\"pre\">get()</span></code><a class=\"heading-anchor\" href=\"#different-exception-from-get\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Managers now return a <a class=\"reference internal\" href=\"/zh-hans/3.1/ref/exceptions/#django.core.exceptions.MultipleObjectsReturned\" title=\"django.core.exceptions.MultipleObjectsReturned\"><code class=\"xref py py-exc docutils literal notranslate\"><span class=\"pre\">MultipleObjectsReturned</span></code></a>\nexception instead of <a class=\"reference external\" href=\"https://docs.python.org/3/library/exceptions.html#AssertionError\" title=\"(in Python v3.14)\"><code class=\"xref py py-exc docutils literal notranslate\"><span class=\"pre\">AssertionError</span></code></a>:</p>\n<p>Old (0.96):</p>\n<div class=\"code-block\" data-language=\"python\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"k\">try</span><span class=\"p\">:</span>\n    <span class=\"n\">Model</span><span class=\"o\">.</span><span class=\"n\">objects</span><span class=\"o\">.</span><span class=\"n\">get</span><span class=\"p\">(</span><span class=\"o\">...</span><span class=\"p\">)</span>\n<span class=\"k\">except</span> <span class=\"ne\">AssertionError</span><span class=\"p\">:</span>\n    <span class=\"n\">handle_the_error</span><span class=\"p\">()</span>\n</code></pre></div>\n<p>New (1.0):</p>\n<div class=\"code-block\" data-language=\"python\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"k\">try</span><span class=\"p\">:</span>\n    <span class=\"n\">Model</span><span class=\"o\">.</span><span class=\"n\">objects</span><span class=\"o\">.</span><span class=\"n\">get</span><span class=\"p\">(</span><span class=\"o\">...</span><span class=\"p\">)</span>\n<span class=\"k\">except</span> <span class=\"n\">Model</span><span class=\"o\">.</span><span class=\"n\">MultipleObjectsReturned</span><span class=\"p\">:</span>\n    <span class=\"n\">handle_the_error</span><span class=\"p\">()</span>\n</code></pre></div>\n</section>\n<section id=\"lazydate-has-been-fired\">\n<h4><code class=\"docutils literal notranslate\"><span class=\"pre\">LazyDate</span></code> has been fired<a class=\"heading-anchor\" href=\"#lazydate-has-been-fired\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>The <code class=\"docutils literal notranslate\"><span class=\"pre\">LazyDate</span></code> helper class no longer exists.</p>\n<p>Default field values and query arguments can both be callable objects, so\ninstances of <code class=\"docutils literal notranslate\"><span class=\"pre\">LazyDate</span></code> can be replaced with a reference to <code class=\"docutils literal notranslate\"><span class=\"pre\">datetime.datetime.now</span></code>:</p>\n<p>Old (0.96):</p>\n<div class=\"code-block\" data-language=\"python\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">Article</span><span class=\"p\">(</span><span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">Model</span><span class=\"p\">):</span>\n    <span class=\"n\">title</span> <span class=\"o\">=</span> <span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">CharField</span><span class=\"p\">(</span><span class=\"n\">maxlength</span><span class=\"o\">=</span><span class=\"mi\">100</span><span class=\"p\">)</span>\n    <span class=\"n\">published</span> <span class=\"o\">=</span> <span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">DateField</span><span class=\"p\">(</span><span class=\"n\">default</span><span class=\"o\">=</span><span class=\"n\">LazyDate</span><span class=\"p\">())</span>\n</code></pre></div>\n<p>New (1.0):</p>\n<div class=\"code-block\" data-language=\"python\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"kn\">import</span><span class=\"w\"> </span><span class=\"nn\">datetime</span>\n\n<span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">Article</span><span class=\"p\">(</span><span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">Model</span><span class=\"p\">):</span>\n    <span class=\"n\">title</span> <span class=\"o\">=</span> <span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">CharField</span><span class=\"p\">(</span><span class=\"n\">max_length</span><span class=\"o\">=</span><span class=\"mi\">100</span><span class=\"p\">)</span>\n    <span class=\"n\">published</span> <span class=\"o\">=</span> <span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">DateField</span><span class=\"p\">(</span><span class=\"n\">default</span><span class=\"o\">=</span><span class=\"n\">datetime</span><span class=\"o\">.</span><span class=\"n\">datetime</span><span class=\"o\">.</span><span class=\"n\">now</span><span class=\"p\">)</span>\n</code></pre></div>\n</section>\n<section id=\"decimalfield-is-new-and-floatfield-is-now-a-proper-float\">\n<h4><code class=\"docutils literal notranslate\"><span class=\"pre\">DecimalField</span></code> is new, and <code class=\"docutils literal notranslate\"><span class=\"pre\">FloatField</span></code> is now a proper float<a class=\"heading-anchor\" href=\"#decimalfield-is-new-and-floatfield-is-now-a-proper-float\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Old (0.96):</p>\n<div class=\"code-block\" data-language=\"python\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">MyModel</span><span class=\"p\">(</span><span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">Model</span><span class=\"p\">):</span>\n    <span class=\"n\">field_name</span> <span class=\"o\">=</span> <span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">FloatField</span><span class=\"p\">(</span><span class=\"n\">max_digits</span><span class=\"o\">=</span><span class=\"mi\">10</span><span class=\"p\">,</span> <span class=\"n\">decimal_places</span><span class=\"o\">=</span><span class=\"mi\">3</span><span class=\"p\">)</span>\n    <span class=\"o\">...</span>\n</code></pre></div>\n<p>New (1.0):</p>\n<div class=\"code-block\" data-language=\"python\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"k\">class</span><span class=\"w\"> </span><span class=\"nc\">MyModel</span><span class=\"p\">(</span><span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">Model</span><span class=\"p\">):</span>\n    <span class=\"n\">field_name</span> <span class=\"o\">=</span> <span class=\"n\">models</span><span class=\"o\">.</span><span class=\"n\">DecimalField</span><span class=\"p\">(</span><span class=\"n\">max_digits</span><span class=\"o\">=</span><span class=\"mi\">10</span><span class=\"p\">,</span> <span class=\"n\">decimal_places</span><span class=\"o\">=</span><span class=\"mi\">3</span><span class=\"p\">)</span>\n    <span class=\"o\">...</span>\n</code></pre></div>\n<p>If you forget to make this change, you will see errors about <code class=\"docutils literal notranslate\"><span class=\"pre\">FloatField</span></code>\nnot taking a <code class=\"docutils literal notranslate\"><span class=\"pre\">max_digits</span></code> attribute in <code class=\"docutils literal notranslate\"><span class=\"pre\">__init__</span></code>, because the new\n<code class=\"docutils literal notranslate\"><span class=\"pre\">FloatField</span></code> takes no precision-related arguments.</p>\n<p>If you're using MySQL or PostgreSQL, no further changes are needed. The\ndatabase column types for <code class=\"docutils literal notranslate\"><span class=\"pre\">DecimalField</span></code> are the same as for the old\n<code class=\"docutils literal notranslate\"><span class=\"pre\">FloatField</span></code>.</p>\n<p>If you're using SQLite, you need to force the database to view the\nappropriate columns as decimal types, rather than floats. To do this, you'll\nneed to reload your data. Do this after you have made the change to using\n<code class=\"docutils literal notranslate\"><span class=\"pre\">DecimalField</span></code> in your code and updated the Django code.</p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Warning</p>\n<p><strong>Back up your database first!</strong></p>\n<p>For SQLite, this means making a copy of the single file that stores the\ndatabase (the name of that file is the <code class=\"docutils literal notranslate\"><span class=\"pre\">DATABASE_NAME</span></code> in your\nsettings.py file).</p>\n</aside>\n<p>To upgrade each application to use a <code class=\"docutils literal notranslate\"><span class=\"pre\">DecimalField</span></code>, you can do the\nfollowing, replacing <code class=\"docutils literal notranslate\"><span class=\"pre\">&lt;app&gt;</span></code> in the code below with each app's name:</p>\n<div class=\"code-block\" data-language=\"console\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code><span class=\"gp\">$ </span>./manage.py<span class=\"w\"> </span>dumpdata<span class=\"w\"> </span>--format<span class=\"o\">=</span>xml<span class=\"w\"> </span>&lt;app&gt;<span class=\"w\"> </span>&gt;<span class=\"w\"> </span>data-dump.xml\n<span class=\"gp\">$ </span>./manage.py<span class=\"w\"> </span>reset<span class=\"w\"> </span>&lt;app&gt;\n<span class=\"gp\">$ </span>./manage.py<span class=\"w\"> </span>loaddata<span class=\"w\"> </span>data-dump.xml\n</code></pre></div>\n<p>注意：</p>\n<ol class=\"arabic simple\">\n<li><p>It's important that you remember to use XML format in the first step of\nthis process. We are exploiting a feature of the XML data dumps that makes\nporting floats to decimals with SQLite possible.</p></li>\n<li><p>In the second step you will be asked to confirm that you are prepared to\nlose the data for the application(s) in question. Say yes; we'll restore\nthis data in the third step.</p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">DecimalField</span></code> is not used in any of the apps shipped with Django prior\nto this change being made, so you do not need to worry about performing\nthis procedure for any of the standard Django models.</p></li>\n</ol>\n<p>If something goes wrong in the above process, just copy your backed up\ndatabase file over the original file and start again.</p>\n</section>\n</section>\n<section id=\"internationalization\">\n<h3>国际化<a class=\"heading-anchor\" href=\"#internationalization\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<section id=\"django-views-i18n-set-language-now-requires-a-post-request\">\n<h4><a class=\"reference internal\" href=\"/zh-hans/3.1/topics/i18n/translation/#django.views.i18n.set_language\" title=\"django.views.i18n.set_language\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">django.views.i18n.set_language()</span></code></a> now requires a POST request<a class=\"heading-anchor\" href=\"#django-views-i18n-set-language-now-requires-a-post-request\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Previously, a GET request was used. The old behavior meant that state (the\nlocale used to display the site) could be changed by a GET request, which is\nagainst the HTTP specification's recommendations. Code calling this view must\nensure that a POST request is now made, instead of a GET. This means you can\nno longer use a link to access the view, but must use a form submission of\nsome kind (e.g. a button).</p>\n</section>\n<section id=\"is-no-longer-in-builtins\">\n<h4><code class=\"docutils literal notranslate\"><span class=\"pre\">_()</span></code> is no longer in builtins<a class=\"heading-anchor\" href=\"#is-no-longer-in-builtins\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">_()</span></code> (the callable object whose name is a single underscore) is no longer\nmonkeypatched into builtins -- that is, it's no longer available magically in\nevery module.</p>\n<p>If you were previously relying on <code class=\"docutils literal notranslate\"><span class=\"pre\">_()</span></code> always being present, you should now\nexplicitly import <code class=\"docutils literal notranslate\"><span class=\"pre\">ugettext</span></code> or <code class=\"docutils literal notranslate\"><span class=\"pre\">ugettext_lazy</span></code>, if appropriate, and alias\nit to <code class=\"docutils literal notranslate\"><span class=\"pre\">_</span></code> yourself:</p>\n<div class=\"code-block\" data-language=\"python\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.utils.translation</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">ugettext</span> <span class=\"k\">as</span> <span class=\"n\">_</span>\n</code></pre></div>\n</section>\n</section>\n<section id=\"http-request-response-objects\">\n<h3>HTTP request/response objects<a class=\"heading-anchor\" href=\"#http-request-response-objects\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<section id=\"dictionary-access-to-httprequest\">\n<h4>Dictionary access to <code class=\"docutils literal notranslate\"><span class=\"pre\">HttpRequest</span></code><a class=\"heading-anchor\" href=\"#dictionary-access-to-httprequest\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">HttpRequest</span></code> objects no longer directly support dictionary-style\naccess; previously, both <code class=\"docutils literal notranslate\"><span class=\"pre\">GET</span></code> and <code class=\"docutils literal notranslate\"><span class=\"pre\">POST</span></code> data were directly\navailable on the <code class=\"docutils literal notranslate\"><span class=\"pre\">HttpRequest</span></code> object (e.g., you could check for a\npiece of form data by using <code class=\"docutils literal notranslate\"><span class=\"pre\">if</span> <span class=\"pre\">'some_form_key'</span> <span class=\"pre\">in</span> <span class=\"pre\">request</span></code> or by\nreading <code class=\"docutils literal notranslate\"><span class=\"pre\">request['some_form_key']</span></code>. This is no longer supported; if\nyou need access to the combined <code class=\"docutils literal notranslate\"><span class=\"pre\">GET</span></code> and <code class=\"docutils literal notranslate\"><span class=\"pre\">POST</span></code> data, use\n<code class=\"docutils literal notranslate\"><span class=\"pre\">request.REQUEST</span></code> instead.</p>\n<p>It is strongly suggested, however, that you always explicitly look in\nthe appropriate dictionary for the type of request you expect to\nreceive (<code class=\"docutils literal notranslate\"><span class=\"pre\">request.GET</span></code> or <code class=\"docutils literal notranslate\"><span class=\"pre\">request.POST</span></code>); relying on the combined\n<code class=\"docutils literal notranslate\"><span class=\"pre\">request.REQUEST</span></code> dictionary can mask the origin of incoming data.</p>\n</section>\n<section id=\"accessing-httpresponse-headers\">\n<h4>Accessing <code class=\"docutils literal notranslate\"><span class=\"pre\">HTTPResponse</span></code> headers<a class=\"heading-anchor\" href=\"#accessing-httpresponse-headers\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">django.http.HttpResponse.headers</span></code> has been renamed to <code class=\"docutils literal notranslate\"><span class=\"pre\">_headers</span></code> and\n<a class=\"reference internal\" href=\"/zh-hans/3.1/ref/request-response/#django.http.HttpResponse\" title=\"django.http.HttpResponse\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">HttpResponse</span></code></a> now supports containment checking directly.\nSo use <code class=\"docutils literal notranslate\"><span class=\"pre\">if</span> <span class=\"pre\">header</span> <span class=\"pre\">in</span> <span class=\"pre\">response:</span></code> instead of <code class=\"docutils literal notranslate\"><span class=\"pre\">if</span> <span class=\"pre\">header</span> <span class=\"pre\">in</span> <span class=\"pre\">response.headers:</span></code>.</p>\n</section>\n</section>\n<section id=\"generic-relations\">\n<h3>通用关系<a class=\"heading-anchor\" href=\"#generic-relations\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<section id=\"generic-relations-have-been-moved-out-of-core\">\n<h4>Generic relations have been moved out of core<a class=\"heading-anchor\" href=\"#generic-relations-have-been-moved-out-of-core\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>The generic relation classes -- <code class=\"docutils literal notranslate\"><span class=\"pre\">GenericForeignKey</span></code> and <code class=\"docutils literal notranslate\"><span class=\"pre\">GenericRelation</span></code>\n-- have moved into the <a class=\"reference internal\" href=\"/zh-hans/3.1/ref/contrib/contenttypes/#module-django.contrib.contenttypes\" title=\"django.contrib.contenttypes: Provides generic interface to installed models.\"><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">django.contrib.contenttypes</span></code></a> module.</p>\n</section>\n</section>\n<section id=\"testing\">\n<h3>测试中<a class=\"heading-anchor\" href=\"#testing\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<section id=\"django-test-client-login-has-changed\">\n<h4><a class=\"reference internal\" href=\"/zh-hans/3.1/topics/testing/tools/#django.test.Client.login\" title=\"django.test.Client.login\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">django.test.Client.login()</span></code></a> has changed<a class=\"heading-anchor\" href=\"#django-test-client-login-has-changed\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Old (0.96):</p>\n<div class=\"code-block\" data-language=\"python\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.test</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">Client</span>\n<span class=\"n\">c</span> <span class=\"o\">=</span> <span class=\"n\">Client</span><span class=\"p\">()</span>\n<span class=\"n\">c</span><span class=\"o\">.</span><span class=\"n\">login</span><span class=\"p\">(</span><span class=\"s1\">&#39;/path/to/login&#39;</span><span class=\"p\">,</span><span class=\"s1\">&#39;myuser&#39;</span><span class=\"p\">,</span><span class=\"s1\">&#39;mypassword&#39;</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>New (1.0):</p>\n<div class=\"code-block\" data-language=\"python\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"c1\"># ... same as above, but then:</span>\n<span class=\"n\">c</span><span class=\"o\">.</span><span class=\"n\">login</span><span class=\"p\">(</span><span class=\"n\">username</span><span class=\"o\">=</span><span class=\"s1\">&#39;myuser&#39;</span><span class=\"p\">,</span> <span class=\"n\">password</span><span class=\"o\">=</span><span class=\"s1\">&#39;mypassword&#39;</span><span class=\"p\">)</span>\n</code></pre></div>\n</section>\n</section>\n<section id=\"management-commands\">\n<h3>Management commands<a class=\"heading-anchor\" href=\"#management-commands\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<section id=\"running-management-commands-from-your-code\">\n<h4>从你的代码中运行管理命令<a class=\"heading-anchor\" href=\"#running-management-commands-from-your-code\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p><a class=\"reference internal\" href=\"/zh-hans/3.1/howto/custom-management-commands/#module-django.core.management\" title=\"django.core.management\"><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">django.core.management</span></code></a> has been greatly refactored.</p>\n<p>Calls to management services in your code now need to use\n<code class=\"docutils literal notranslate\"><span class=\"pre\">call_command</span></code>. For example, if you have some test code that calls flush and\nload_data:</p>\n<div class=\"code-block\" data-language=\"python\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.core</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">management</span>\n<span class=\"n\">management</span><span class=\"o\">.</span><span class=\"n\">flush</span><span class=\"p\">(</span><span class=\"n\">verbosity</span><span class=\"o\">=</span><span class=\"mi\">0</span><span class=\"p\">,</span> <span class=\"n\">interactive</span><span class=\"o\">=</span><span class=\"kc\">False</span><span class=\"p\">)</span>\n<span class=\"n\">management</span><span class=\"o\">.</span><span class=\"n\">load_data</span><span class=\"p\">([</span><span class=\"s1\">&#39;test_data&#39;</span><span class=\"p\">],</span> <span class=\"n\">verbosity</span><span class=\"o\">=</span><span class=\"mi\">0</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>...you'll need to change this code to read:</p>\n<div class=\"code-block\" data-language=\"python\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python code\"><code><span class=\"kn\">from</span><span class=\"w\"> </span><span class=\"nn\">django.core</span><span class=\"w\"> </span><span class=\"kn\">import</span> <span class=\"n\">management</span>\n<span class=\"n\">management</span><span class=\"o\">.</span><span class=\"n\">call_command</span><span class=\"p\">(</span><span class=\"s1\">&#39;flush&#39;</span><span class=\"p\">,</span> <span class=\"n\">verbosity</span><span class=\"o\">=</span><span class=\"mi\">0</span><span class=\"p\">,</span> <span class=\"n\">interactive</span><span class=\"o\">=</span><span class=\"kc\">False</span><span class=\"p\">)</span>\n<span class=\"n\">management</span><span class=\"o\">.</span><span class=\"n\">call_command</span><span class=\"p\">(</span><span class=\"s1\">&#39;loaddata&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;test_data&#39;</span><span class=\"p\">,</span> <span class=\"n\">verbosity</span><span class=\"o\">=</span><span class=\"mi\">0</span><span class=\"p\">)</span>\n</code></pre></div>\n</section>\n<section id=\"subcommands-must-now-precede-options\">\n<h4>Subcommands must now precede options<a class=\"heading-anchor\" href=\"#subcommands-must-now-precede-options\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">django-admin.py</span></code> and <code class=\"docutils literal notranslate\"><span class=\"pre\">manage.py</span></code> now require subcommands to precede\noptions. So:</p>\n<div class=\"code-block\" data-language=\"console\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code><span class=\"gp\">$ </span>django-admin.py<span class=\"w\"> </span>--settings<span class=\"o\">=</span>foo.bar<span class=\"w\"> </span>runserver\n</code></pre></div>\n<p>...no longer works and should be changed to:</p>\n<div class=\"code-block\" data-language=\"console\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code><span class=\"gp\">$ </span>django-admin.py<span class=\"w\"> </span>runserver<span class=\"w\"> </span>--settings<span class=\"o\">=</span>foo.bar\n</code></pre></div>\n</section>\n</section>\n<section id=\"syndication\">\n<h3>联合<a class=\"heading-anchor\" href=\"#syndication\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<section id=\"feed-init-has-changed\">\n<h4><code class=\"docutils literal notranslate\"><span class=\"pre\">Feed.__init__</span></code> has changed<a class=\"heading-anchor\" href=\"#feed-init-has-changed\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>The <code class=\"docutils literal notranslate\"><span class=\"pre\">__init__()</span></code> method of the syndication framework's <code class=\"docutils literal notranslate\"><span class=\"pre\">Feed</span></code> class now\ntakes an <code class=\"docutils literal notranslate\"><span class=\"pre\">HttpRequest</span></code> object as its second parameter, instead of the feed's\nURL. This allows the syndication framework to work without requiring the sites\nframework. This only affects code that subclasses <code class=\"docutils literal notranslate\"><span class=\"pre\">Feed</span></code> and overrides the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">__init__()</span></code> method, and code that calls <code class=\"docutils literal notranslate\"><span class=\"pre\">Feed.__init__()</span></code> directly.</p>\n</section>\n</section>\n<section id=\"data-structures\">\n<h3>Data structures<a class=\"heading-anchor\" href=\"#data-structures\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<section id=\"sorteddictfromlist-is-gone\">\n<h4><code class=\"docutils literal notranslate\"><span class=\"pre\">SortedDictFromList</span></code> is gone<a class=\"heading-anchor\" href=\"#sorteddictfromlist-is-gone\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">django.newforms.forms.SortedDictFromList</span></code> was removed.\n<code class=\"docutils literal notranslate\"><span class=\"pre\">django.utils.datastructures.SortedDict</span></code> can now be instantiated with\na sequence of tuples.</p>\n<p>To update your code:</p>\n<ol class=\"arabic simple\">\n<li><p>Use <code class=\"docutils literal notranslate\"><span class=\"pre\">django.utils.datastructures.SortedDict</span></code> wherever you were\nusing <code class=\"docutils literal notranslate\"><span class=\"pre\">django.newforms.forms.SortedDictFromList</span></code>.</p></li>\n<li><p>Because <code class=\"docutils literal notranslate\"><span class=\"pre\">django.utils.datastructures.SortedDict.copy</span></code> doesn't\nreturn a deepcopy as <code class=\"docutils literal notranslate\"><span class=\"pre\">SortedDictFromList.copy()</span></code> did, you will need\nto update your code if you were relying on a deepcopy. Do this by using\n<code class=\"docutils literal notranslate\"><span class=\"pre\">copy.deepcopy</span></code> directly.</p></li>\n</ol>\n</section>\n</section>\n<section id=\"database-backend-functions\">\n<h3>Database backend functions<a class=\"heading-anchor\" href=\"#database-backend-functions\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<section id=\"database-backend-functions-have-been-renamed\">\n<h4>Database backend functions have been renamed<a class=\"heading-anchor\" href=\"#database-backend-functions-have-been-renamed\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Almost <em>all</em> of the database backend-level functions have been renamed and/or\nrelocated. None of these were documented, but you'll need to change your code\nif you're using any of these functions, all of which are in <a class=\"reference internal\" href=\"/zh-hans/3.1/topics/db/#module-django.db\" title=\"django.db\"><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">django.db</span></code></a>:</p>\n<div class=\"table-scroll\" role=\"region\" tabindex=\"0\" aria-label=\"Table\"><table class=\"docutils align-default\">\n<thead>\n<tr class=\"row-odd\"><th class=\"head\"><p>Old (0.96)</p></th>\n<th class=\"head\"><p>New (1.0)</p></th>\n</tr>\n</thead>\n<tbody>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">backend.get_autoinc_sql</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">connection.ops.autoinc_sql</span></code></p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">backend.get_date_extract_sql</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">connection.ops.date_extract_sql</span></code></p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">backend.get_date_trunc_sql</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">connection.ops.date_trunc_sql</span></code></p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">backend.get_datetime_cast_sql</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">connection.ops.datetime_cast_sql</span></code></p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">backend.get_deferrable_sql</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">connection.ops.deferrable_sql</span></code></p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">backend.get_drop_foreignkey_sql</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">connection.ops.drop_foreignkey_sql</span></code></p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">backend.get_fulltext_search_sql</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">connection.ops.fulltext_search_sql</span></code></p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">backend.get_last_insert_id</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">connection.ops.last_insert_id</span></code></p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">backend.get_limit_offset_sql</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">connection.ops.limit_offset_sql</span></code></p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">backend.get_max_name_length</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">connection.ops.max_name_length</span></code></p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">backend.get_pk_default_value</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">connection.ops.pk_default_value</span></code></p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">backend.get_random_function_sql</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">connection.ops.random_function_sql</span></code></p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">backend.get_sql_flush</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">connection.ops.sql_flush</span></code></p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">backend.get_sql_sequence_reset</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">connection.ops.sequence_reset_sql</span></code></p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">backend.get_start_transaction_sql</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">connection.ops.start_transaction_sql</span></code></p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">backend.get_tablespace_sql</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">connection.ops.tablespace_sql</span></code></p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">backend.quote_name</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">connection.ops.quote_name</span></code></p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">backend.get_query_set_class</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">connection.ops.query_set_class</span></code></p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">backend.get_field_cast_sql</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">connection.ops.field_cast_sql</span></code></p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">backend.get_drop_sequence</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">connection.ops.drop_sequence_sql</span></code></p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">backend.OPERATOR_MAPPING</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">connection.operators</span></code></p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">backend.allows_group_by_ordinal</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">connection.features.allows_group_by_ordinal</span></code></p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">backend.allows_unique_and_pk</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">connection.features.allows_unique_and_pk</span></code></p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">backend.autoindexes_primary_keys</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">connection.features.autoindexes_primary_keys</span></code></p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">backend.needs_datetime_string_cast</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">connection.features.needs_datetime_string_cast</span></code></p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">backend.needs_upper_for_iops</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">connection.features.needs_upper_for_iops</span></code></p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">backend.supports_constraints</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">connection.features.supports_constraints</span></code></p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">backend.supports_tablespaces</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">connection.features.supports_tablespaces</span></code></p></td>\n</tr>\n<tr class=\"row-even\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">backend.uses_case_insensitive_names</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">connection.features.uses_case_insensitive_names</span></code></p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">backend.uses_custom_queryset</span></code></p></td>\n<td><p><code class=\"docutils literal notranslate\"><span class=\"pre\">connection.features.uses_custom_queryset</span></code></p></td>\n</tr>\n</tbody>\n</table>\n</div>\n</section>\n</section>\n</section>","rootId":"porting-your-apps-from-django-0-96-to-1-0","toc":[{"title":"Common changes","anchor":"common-changes","children":[{"title":"Use Unicode","anchor":"use-unicode","children":[]},{"title":"模型","anchor":"models","children":[{"title":"maxlength 重命名为 max_length","anchor":"rename-maxlength-to-max-length","children":[]},{"title":"Replace __str__ with __unicode__","anchor":"replace-str-with-unicode","children":[]},{"title":"移除 prepopulated_from","anchor":"remove-prepopulated-from","children":[]},{"title":"移除 core","anchor":"remove-core","children":[]},{"title":"用 admin.py 替换  class Admin:","anchor":"replace-class-admin-with-admin-py","children":[]},{"title":"例如","anchor":"example","children":[]}]},{"title":"The Admin","anchor":"the-admin","children":[{"title":"Use new inline syntax","anchor":"use-new-inline-syntax","children":[]},{"title":"Simplify fields, or use fieldsets","anchor":"simplify-fields-or-use-fieldsets","children":[]}]},{"title":"URLs","anchor":"urls","children":[{"title":"Update your root urls.py","anchor":"update-your-root-urls-py","children":[]}]},{"title":"视图","anchor":"views","children":[{"title":"Use django.forms instead of newforms","anchor":"use-django-forms-instead-of-newforms","children":[]},{"title":"Handle uploaded files using the new API","anchor":"handle-uploaded-files-using-the-new-api","children":[]},{"title":"Work with file fields using the new API","anchor":"work-with-file-fields-using-the-new-api","children":[]},{"title":"Use Paginator instead of ObjectPaginator","anchor":"use-paginator-instead-of-objectpaginator","children":[]}]},{"title":"模板","anchor":"templates","children":[{"title":"Learn to love autoescaping","anchor":"learn-to-love-autoescaping","children":[]}]}]},{"title":"Less-common changes","anchor":"less-common-changes","children":[{"title":"信号","anchor":"signals","children":[]},{"title":"评论","anchor":"comments","children":[]},{"title":"模板标签","anchor":"template-tags","children":[{"title":"spaceless tag","anchor":"spaceless-tag","children":[]}]},{"title":"Local flavors","anchor":"local-flavors","children":[{"title":"U.S. local flavor","anchor":"u-s-local-flavor","children":[]}]},{"title":"会话","anchor":"sessions","children":[{"title":"Getting a new session key","anchor":"getting-a-new-session-key","children":[]}]},{"title":"辅助工具","anchor":"fixtures","children":[{"title":"Loading a row no longer calls save()","anchor":"loading-a-row-no-longer-calls-save","children":[]}]},{"title":"配置","anchor":"settings","children":[{"title":"Better exceptions","anchor":"better-exceptions","children":[]},{"title":"LOGIN_URL has moved","anchor":"login-url-has-moved","children":[]},{"title":"APPEND_SLASH behavior has been updated","anchor":"append-slash-behavior-has-been-updated","children":[]}]},{"title":"Smaller model changes","anchor":"smaller-model-changes","children":[{"title":"Different exception from get()","anchor":"different-exception-from-get","children":[]},{"title":"LazyDate has been fired","anchor":"lazydate-has-been-fired","children":[]},{"title":"DecimalField is new, and FloatField is now a proper float","anchor":"decimalfield-is-new-and-floatfield-is-now-a-proper-float","children":[]}]},{"title":"国际化","anchor":"internationalization","children":[{"title":"django.views.i18n.set_language() now requires a POST request","anchor":"django-views-i18n-set-language-now-requires-a-post-request","children":[]},{"title":"_() is no longer in builtins","anchor":"is-no-longer-in-builtins","children":[]}]},{"title":"HTTP request/response objects","anchor":"http-request-response-objects","children":[{"title":"Dictionary access to HttpRequest","anchor":"dictionary-access-to-httprequest","children":[]},{"title":"Accessing HTTPResponse headers","anchor":"accessing-httpresponse-headers","children":[]}]},{"title":"通用关系","anchor":"generic-relations","children":[{"title":"Generic relations have been moved out of core","anchor":"generic-relations-have-been-moved-out-of-core","children":[]}]},{"title":"测试中","anchor":"testing","children":[{"title":"django.test.Client.login() has changed","anchor":"django-test-client-login-has-changed","children":[]}]},{"title":"Management commands","anchor":"management-commands","children":[{"title":"从你的代码中运行管理命令","anchor":"running-management-commands-from-your-code","children":[]},{"title":"Subcommands must now precede options","anchor":"subcommands-must-now-precede-options","children":[]}]},{"title":"联合","anchor":"syndication","children":[{"title":"Feed.__init__ has changed","anchor":"feed-init-has-changed","children":[]}]},{"title":"Data structures","anchor":"data-structures","children":[{"title":"SortedDictFromList is gone","anchor":"sorteddictfromlist-is-gone","children":[]}]},{"title":"Database backend functions","anchor":"database-backend-functions","children":[{"title":"Database backend functions have been renamed","anchor":"database-backend-functions-have-been-renamed","children":[]}]}]}],"breadcrumbs":[{"docname":"releases/index","title":"发行说明","url":"/zh-hans/3.1/releases/"},{"docname":"releases/1.0","title":"Django 1.0 版本发行说明","url":"/zh-hans/3.1/releases/1.0/"}],"prev":{"docname":"releases/1.0","title":"Django 1.0 版本发行说明","url":"/zh-hans/3.1/releases/1.0/"},"next":{"docname":"releases/0.96","title":"Django 0.96 版本发行说明","url":"/zh-hans/3.1/releases/0.96/"},"formats":{"html":"/zh-hans/3.1/releases/1.0-porting-guide/","markdown":"/zh-hans/3.1/releases/1.0-porting-guide.md","json":"/zh-hans/3.1/releases/1.0-porting-guide.json"},"source":"https://github.com/django/django/blob/stable/3.1.x/docs/releases/1.0-porting-guide.txt","official":"https://docs.djangoproject.com/zh-hans/3.1/releases/1.0-porting-guide/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0"],"inLocales":["en","zh-hans","fr","ja","id","pt-br","ko","es","el","pl"]}