aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/learn/server-side/django/deployment/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/learn/server-side/django/deployment/index.html')
-rw-r--r--files/zh-cn/learn/server-side/django/deployment/index.html675
1 files changed, 675 insertions, 0 deletions
diff --git a/files/zh-cn/learn/server-side/django/deployment/index.html b/files/zh-cn/learn/server-side/django/deployment/index.html
new file mode 100644
index 0000000000..fe582da51f
--- /dev/null
+++ b/files/zh-cn/learn/server-side/django/deployment/index.html
@@ -0,0 +1,675 @@
+---
+title: 'Django 教程 11: 部署 Django 到生产环境'
+slug: learn/Server-side/Django/Deployment
+translation_of: Learn/Server-side/Django/Deployment
+---
+<div>{{LearnSidebar}}</div>
+
+<div>{{PreviousMenuNext("Learn/Server-side/Django/Testing", "Learn/Server-side/Django/web_application_security", "Learn/Server-side/Django")}}</div>
+
+<p class="summary">现<font><font>在,您已经创建(并测试)了一个令人敬畏的</font></font><a href="https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Tutorial_local_library_website" style='color: rgb(63, 135, 166); margin: 0px; padding: 0px; border: 0px; text-decoration: none; font-family: "Open Sans", arial, x-locale-body, sans-serif; font-size: 20px; font-style: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; background-color: rgb(255, 255, 255);'><font><font>LocalLibrary</font></font></a><font><font>网站,如果您希望将其安装在公共Web服务器上,以便图书馆工作人员和成员可以通过Internet访问它。</font><font>本文概述了如何找到主机来部署您的网站,以及您需要做什么才能让您的网站准备好生产</font></font>。</p>
+
+<table class="learn-box standard-table">
+ <tbody>
+ <tr>
+ <th scope="row"><strong style='background-color: #ffe8d4; color: #333333; display: inline !important; float: none; font-family: "Open Sans",arial,x-locale-body,sans-serif; font-size: medium; font-style: normal; font-weight: 700; letter-spacing: normal; text-align: left; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: normal;'>先决条件</strong>:</th>
+ <td>完成所有先前的教程,包括:
+ <p><a href="https://developer.mozilla.org/zh-CN/docs/Learn/Server-side/Django/Testing">在线教学 10:测试 Django 的 Web 应用</a></p>
+ </td>
+ </tr>
+ <tr>
+ <th scope="row"><strong style='background-color: #ffe8d4; color: #333333; display: inline !important; float: none; font-family: "Open Sans",arial,x-locale-body,sans-serif; font-size: medium; font-style: normal; font-weight: 700; letter-spacing: normal; text-align: left; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: normal;'>目的</strong>:</th>
+ <td>了解您可以在何处以及如何将Django应用程序部署到生产环境。</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="概述">概述</h2>
+
+<p><span style='background-color: #ffffff; color: #333333; display: inline !important; float: none; font-family: "Open Sans",arial,x-locale-body,sans-serif; font-size: medium; font-style: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: normal;'>一旦您的网站完成(或完成“足够”开始公开测试),您将需要将其托管在比您的个人开发计算机更公开和可访问的地方。</span></p>
+
+<p style='font-style: normal; margin: 0px 0px 24px; padding: 0px; border: 0px; max-width: 42rem; color: rgb(51, 51, 51); font-family: "Open Sans", arial, x-locale-body, sans-serif; font-size: medium; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-style: initial;'><font><font>到目前为止,您一直在开发环境中工作,使用Django开发Web服务器将您的站点共享到本地浏览器/网络,并使用暴露调试和其他私人信息的(不安全)开发设置运行您的网站。</font><font>在您可以从外部托管网站之前,您首先必须:</font></font></p>
+
+<ul style='font-style: normal; margin: 0px 0px 24px; padding: 0px 0px 0px 40px; border: 0px; max-width: 42rem; color: rgb(51, 51, 51); font-family: "Open Sans", arial, x-locale-body, sans-serif; font-size: medium; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-style: initial;'>
+</ul>
+
+<ul>
+ <li>对你的项目设置(project settings)做一定的修改</li>
+ <li>选择一个用来托管Django app的环境</li>
+ <li>选择一个用来托管所有静态文件的环境</li>
+ <li>设置一个产品级的设施来为你的网站服务</li>
+</ul>
+
+<p style='font-style: normal; margin: 0px 0px 24px; padding: 0px; border: 0px; max-width: 42rem; color: rgb(51, 51, 51); font-family: "Open Sans", arial, x-locale-body, sans-serif; font-size: medium; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-style: initial;'><font><font>本教程为您选择托管站点提供了一些指导,简要概述了为了让您的Django应用程序可用于生产需要做什么以及如何将LocalLibrary网站安装到</font></font><a class="external external-icon" href="https://www.heroku.com/" rel="noopener" style="font-style: normal !important; color: rgb(63, 135, 166); margin: 0px; padding: 0px; border: 0px; text-decoration: none; white-space: pre-line;"><font><font>Heroku</font></font></a><font><font>云托管上服务。</font></font></p>
+
+<h2 id="什么是生产环境">什么是生产环境?</h2>
+
+<p>生产环境是一个由服务器电脑提供的环境,你将在这里运行你的网站,为外部使用提供服务。生产环境包括:</p>
+
+<ul>
+ <li>网站运行所需要的电脑硬件</li>
+ <li>操作系统 (例如 Linux, Windows).</li>
+ <li>编程语言运行库和框架库,在其上编写您的网站。</li>
+ <li>用于提供页面和其他内容的Web服务器(例如Nginx,Apache)。</li>
+ <li>在 Django 网站和 Web 服务器之间,传递“动态”请求的应用程序服务器。</li>
+ <li>您的网站所依赖的数据库。</li>
+</ul>
+
+<div class="note">
+<p><strong>注意</strong>: 根据您的生产配置方式,您可能还有反向代理,负载均衡器等。</p>
+</div>
+
+<p>服务器计算机可以位于您的场所,并通过快速链接连接到 Internet,但使用托管“在云中”的计算机更为常见。这实际上意味着,您的代码在托管公司的数据中心的某台远程计算机(或可能是“虚拟”计算机)上运行。远程服务器通常会以特定价格,提供一些保证级别的计算资源(例如CPU,RAM,存储器等)和互联网连接。</p>
+
+<p>这种可远程访问的计算/网络硬件,称为基础架构即服务(IaaS)。许多IaaS供应商,提供预安装特定操作系统的选项,您必须在其上安装生产环境的其他组件。其他供应商允许您选择功能更全面的环境,可能包括完整的 Django ,和 Web 服务器设置。</p>
+
+<div class="note">
+<p><strong>注意:</strong> 预构建环境可以使您的网站设置变得非常简单,因为它们会减少配置,但可用选项可能会限制您使用不熟悉的服务器(或其他组件),并且可能基于较旧版本的操作系统。通常最好自己安装组件,以便获得所需的组件,当您需要升级系统的某些部分时,您就知道从哪里开始!</p>
+</div>
+
+<p>其他托管服务提供商,支持 Django 作为平台即服务(PaaS)产品的一部分。在这种托管中,您不必担心大多数生产环境(Web 服务器,应用程序服务器,负载平衡器),因为主机平台会为您处理这些(以及为了扩展您的应用程序,而需要做的大部分工作)。这使得部署非常简单,因为您只需要专注于 Web 应用程序,而不是所有其他服务器的基础结构。</p>
+
+<p>相对于 PaaS,一些开发人员会选择 IaaS 所提供的更高灵活性,而其他开发人员,则欣赏 PaaS 降低的维护开销,和更轻松地扩展。当您开始使用时,在 PaaS 系统上设置您的网站,要容易得多,因此我们将在本教程中这么做。</p>
+
+<div class="note">
+<p><strong>提示:</strong> 如果您选择一个 Python/Django 友好的托管服务提供商,他们应该提供有关如何使用不同配置的网络服务器,应用服务器,反向代理等设置 Django 网站的说明(如果您选择 PaaS,这就没有关系了)。例如,<a href="https://www.digitalocean.com/community/tutorials?q=django">Digital Ocean Django 社区文档 </a>中的各种配置,有许多手把手指南。</p>
+</div>
+
+<h2 id="选择托管服务提供商">选择托管服务提供商</h2>
+
+<p>已知有超过100个托管服务提供商,积极支持或与 Django 合作(您可以在 <a href="http://djangofriendly.com/hosts/">Djangofriendly hosts </a>主机上,找到相当广泛的列表)。这些供应商提供不同类型的环境(IaaS,PaaS),以及不同价格、不同级别的计算和网络资源。</p>
+
+<p>选择主机时需要考虑的一些事项:</p>
+
+<ul>
+ <li>您的网站可能有多忙,以及满足该需求,所需的数据和计算资源的成本。</li>
+ <li>水平扩展(添加更多机器)和垂直扩展(升级到更强大的机器)的支持级别,以及这样做的成本。</li>
+ <li>供应商的数据中心位于何处,因此访问可能是最快的。</li>
+ <li>主机的历史正常运行时间,和停机时间的表现。</li>
+ <li>用于管理站点的工具 - 易于使用且安全(例如 SFTP 相比于 FTP)。</li>
+ <li>用于监控服务器的内置框架。</li>
+ <li>已知限制。有些主机会故意阻止某些服务(例如电子邮件)。其他在某些价格层中,仅提供一定时数的“实时时间”,或者仅提供少量存储空间。</li>
+ <li>额外的好处。一些提供商将提供免费域名和 SSL 证书支持,否则您将不得不为此支付费用。</li>
+ <li>您所依赖的“免费”等级,是否会随着时间的推移而过期,以及迁移到更昂贵等级的成本,是否意味着,您最好一开始就使用其他服务!</li>
+</ul>
+
+<p>当你刚开始时,好消息是,有很多网站提供了 “免费” 的 “评估”、“开发者” 或 “爱好者” 计算环境。这些始终是资源相当受限/有限的环境,您需要注意,它们可能会在广告期限后过期。然而,它们非常适合在真实环境中,测试低流量站点,并且可以在您的站点变得更加繁忙时,付费取得更多资源,并轻松迁移。此类别中的热门选择包括<a href="https://www.heroku.com/">Heroku</a>, <a href="https://www.pythonanywhere.com/">Python Anywhere</a>, <a href="http://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/billing-free-tier.html">Amazon Web Services</a>, <a href="https://azure.microsoft.com/en-us/pricing/details/app-service/">Microsoft Azure</a> 等。</p>
+
+<p>许多提供商还有“基本”层,可提供更多有用的计算能力和更少的限制。<a href="https://www.digitalocean.com/">Digital Ocean</a> 和 <a href="https://www.pythonanywhere.com/">Python Anywhere</a> ,就是流行的托管服务提供商的例子,提供相对便宜的基本计算等级(每月 5 美元到 10 美元不等)。</p>
+
+<div class="note">
+<p><strong>注意:</strong> 请记住,价格不是唯一的选择标准。如果您的网站成功,可能会发现,可扩展性是最重要的考虑因素。</p>
+</div>
+
+<h2 id="让您的网站准备好发布">让您的网站准备好发布</h2>
+
+<p>使用 django-admin 和 manage.py 工具创建的 Django 骨架网站,是为了使开发更容易而配置的。出于安全性或性能原因,许多 Django 项目设置(在<strong>settings.py</strong>中指定),在生产应该是不同的。</p>
+
+<div class="note">
+<p><strong>提示:</strong> 通常有一个单独的 <strong>settings.py</strong> 文件用于生产环境,并从单独的文件或环境变量,导入敏感设置。即使其他源代码在公共存储库中可用,也应保护此文件。</p>
+</div>
+
+<p>您必须检查的关键设置是:</p>
+
+<ul>
+ <li><code>DEBUG</code>. 这应该在生产环境中设置为 <code>False</code>(<code>DEBUG = False</code>)。这将停止显示敏感/机密调试跟踪和变量信息。</li>
+ <li><code>SECRET_KEY</code>. 这是用于CRSF保护等的大随机值。重要的是,生产中使用的密钥,不应在源代码管理中、或在生产服务器外部可访问。 Django文档表明,可能最好从环境变量加载,或从仅供服务的文件中读取。
+ <pre class="notranslate"># Read SECRET_KEY from an environment variable
+import os
+SECRET_KEY = os.environ['SECRET_KEY']
+
+#OR
+
+#Read secret key from a file
+with open('/etc/secret_key.txt') as f:
+ SECRET_KEY = f.read().strip()</pre>
+ </li>
+</ul>
+
+<p>让我们更改 LocalLibrary 应用程序,以便我们从环境变量中,读取<code>SECRET_KEY</code> 和 <code>DEBUG</code>变量(如果已定义),否则使用配置文件中的默认值。</p>
+
+<p>打开 <strong>/locallibrary/settings.py</strong>,禁用原始的<code>SECRET_KEY</code>配置,并加入如下以<strong>粗体</strong>显示的几行。在开发过程中,不会为密钥指定环境变量,因此将使用默认值(在此处使用的密钥,或密钥“泄漏”无关紧要,因为您不会在生产环境中使用它)。</p>
+
+<pre class="brush: python notranslate"># SECURITY WARNING: keep the secret key used in production secret!
+# SECRET_KEY = 'cg#p$g+j9tax!#a3cup@1$8obt2_+&amp;k3q+pmu)5%asj6yjpkag'
+<strong>import os</strong>
+<strong>SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'cg#p$g+j9tax!#a3cup@1$8obt2_+&amp;k3q+pmu)5%asj6yjpkag')</strong>
+</pre>
+
+<p>然后注释掉现有的<code>DEBUG</code>设置,并如下所示,添加新的一行。</p>
+
+<pre class="brush: python notranslate"># SECURITY WARNING: don't run with debug turned on in production!
+# DEBUG = True
+<strong>DEBUG = bool( os.environ.get('DJANGO_DEBUG', True) )</strong>
+</pre>
+
+<p>默认情况下,<code>DEBUG</code>的值为<code>True</code>,但如果<code>DJANGO_DEBUG</code>环境变量的值,设置为空字符串,则为<code>False</code>,例如,<code>DJANGO_DEBUG=''</code>。</p>
+
+<div class="note">
+<p><strong>注意</strong>: 如果我们可以直接将<code>DJANGO_DEBUG</code>环境变量设置为<code>True</code>或<code>False</code>,而不是分别使用“any string”或“empty string”,那将更直观。不幸的是,环境变量值存储为 Python 字符串,计算结果为 <code>False</code> 的唯一字符串,是空字符串(例如<code>bool('')==False</code>)。</p>
+</div>
+
+<p><a href="https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/">部署清单(Django文档)</a>中,提供了您可能要更改的完整设置清单。您还可以使用下面的终端命令,列出其中的一些:</p>
+
+<pre class="brush: python notranslate">python3 manage.py check --deploy
+</pre>
+
+<h2 id="示例:在Heroku上安装LocalLibrary">示例:在Heroku上安装LocalLibrary</h2>
+
+<p>本节提供了如何在 <a href="http://heroku.com">Heroku PaaS cloud </a>云上安装 LocalLibrary 的实际演示。</p>
+
+<h3 id="为何选择Heroku?">为何选择Heroku?</h3>
+
+<p>Heroku 是运行时间最长,且最受欢迎的基于云的 PaaS 服务之一。它最初只支持 Ruby 应用程序,但现在可用于托管来自许多编程环境的应用程序,包括 Django!</p>
+
+<p>我们选择使用Heroku有以下几个原因:</p>
+
+<ul>
+ <li>Heroku 有一个真正免费的免费套餐<a href="https://www.heroku.com/pricing">free tier</a> (尽管有一些限制)。</li>
+ <li>作为 PaaS,Heroku 为我们提供了大量的 Web 基础架构。这使得入门更加容易,因为您不必担心 Heroku 为我们提供的服务器,负载平衡器,反向代理或任何其他 Web 基础结构。</li>
+ <li>虽然它确实有一些限制,但这些不会影响本教程的应用程序。例如:
+ <ul>
+ <li>Heroku只提供短期储存,因此用户上传的文件无法安全地存储在 Heroku 本身。</li>
+ <li>如果半小时内没有请求,免费套餐将使不活动的网络应用程序进入睡眠。然后,该网站可能需要几秒钟才能被唤醒。</li>
+ <li>免费套餐将您网站运行的时间,限制为每月一定的小时数(不包括网站“睡着”的时间)。这对于低使用/演示站点来说很好,但如果需要100%的正常运行时间则不适用。</li>
+ <li>在 <a href="https://devcenter.heroku.com/articles/limits">Limits</a> (Heroku 文档) 中列出了其他限制。</li>
+ </ul>
+ </li>
+ <li>大多数情况下它只是能工作,如果你最终喜欢它,扩展你的应用程序非常容易。</li>
+</ul>
+
+<p>虽然 Heroku 非常适合用于此演示,但它可能并不适合您的真实网站。 Heroku可以轻松设置和扩展,但代价是灵活性较低,而且一旦退​​出免费套餐,可能会花费更多。</p>
+
+<h3 id="Heroku是如何工作的?">Heroku是如何工作的?</h3>
+
+<p>Heroku 在一个或多个 “<a href="https://devcenter.heroku.com/articles/dynos">Dynos</a>” 中,运行Django网站,这是一个独立的虚拟化 Unix 容器,提供运行应用程序所需的环境。<a href="https://devcenter.heroku.com/articles/dynos">Dynos </a>是完全隔离的,并且有一个短暂的文件系统(一个短暂的文件系统,每次dyno 重新启动时,都会清理/清空)。 Dynos 默认共享的唯一内容,是应用程序配置变量。 Heroku 内部使用负载均衡器,将 Web 流量分配给所有 “web” dynos。由于他们之间没有任何共享,Heroku可以通过添加更多 dynos ,来水平扩展应用程序(当然,您可能还需要扩展数据库,以接受其他连接)。</p>
+
+<p>由于文件系统是暂时的,因此无法直接安装应用程序所需的服务(例如数据库,队列,缓存系统,存储,电子邮件服务等)。取代的是,Heroku Web 应用程序,使用 Heroku 或第三方作为独立“附加组件”提供的支持服务。一旦连接到 Web 应用程序,dynos 就会使用应用程序配置变量中包含的信息,来访问服务。</p>
+
+<p>为了执行您的应用程序,Heroku 需要能够设置适当的环境,和依赖关系,并了解它是如何启动的。对于 Django 应用程序而言,我们在一些文本文件中提供此信息:</p>
+
+<ul>
+ <li><strong>runtime.txt</strong>:<strong> </strong>要使用的编程语言和版本。</li>
+ <li><strong>requirements.txt</strong>: Python组件依赖项,包括Django。</li>
+ <li><strong>Procfile</strong>: 启动 Web 应用程序要执行的进程列表。对于Django,这通常是 Gunicorn Web 应用程序服务器(带有 <code>.wsgi </code>脚本)。</li>
+ <li><strong>wsgi.py</strong>: 在 Heroku 环境中,调用我们的Django 应用程序的 <a href="http://wsgi.readthedocs.io/en/latest/what.html">WSGI </a>配置。</li>
+</ul>
+
+<p>开发人员使用特殊的客户端应用程序/终端与 Heroku 交互,这很像Unix bash 脚本。这允许您上传存在 git 储存库中的代码,检查正在运行的进程,查看日志,设置配置变量等等!</p>
+
+<p>为了让我们的应用程序在Heroku上工作,我们需要将我们的 Django Web 应用程序,放入git储存库,添加上面的文件,集成数据库附加组件,并进行更改,以正确处理静态文件。</p>
+
+<p>完成所有操作后,我们可以设置 Heroku 帐户,获取 Heroku 客户端,并使用它来安装我们的网站。</p>
+
+<div class="note">
+<p><strong>注意:</strong> 以下说明反映了在撰写本书时,如何使用 Heroku。如果 Heroku 显着改变了他们的操作过程,您可能希望检查他们的设置文档:<a href="https://devcenter.heroku.com/articles/getting-started-with-python#introduction">在Heroku上开始使用 Django</a>。</p>
+</div>
+
+<p>就是您一开始所需的所有概述(请参阅 <a href="https://devcenter.heroku.com/articles/how-heroku-works">Heroku 如何工作</a>,以获取更全面的指南)。</p>
+
+<h3 id="在_Github_中创建应用程序储存库">在 Github 中创建应用程序储存库</h3>
+
+<p>Heroku 与 <strong>git</strong> 源代码版本控制系统紧密集成,使用它来上传/同步您对实时系统所做的任何更改。它通过添加一个名为 heroku 的新的heroku “远程” 储存库,来指向 Heroku 云上的源储存库。在开发期间,您使用 git 在“主”储存库中储存更改。如果要部署站点,请将更改同步到 Heroku 储存库。</p>
+
+<div class="note">
+<p><strong>注意:</strong> 如果您习惯于遵循良好的软件开发实践,那么您可能已经在使用 git,或其他一些 SCM 系统。如果您已有 git 储存库,则可以跳过此步骤。</p>
+</div>
+
+<p>有很多方法可以使用 git,但最简单的方法之一,是首先在 <a href="https://github.com/">Github</a> 上建立一个帐户,在那里创建储存库,然后将它同步到本地:</p>
+
+<ol>
+ <li>访问 <a href="https://github.com/">https://github.com/</a> 并创建一个帐户。</li>
+ <li>登录后,点击顶部工具栏中的 + 链接,然后选择新建储存库 <strong>New repository</strong>。</li>
+ <li>填写此表单上的所有字段。虽然这些不是强制性的,但强烈建议使用它们。
+ <ul>
+ <li>输入新的储存库名称(例如 django_local_library)和描述(例如 “用 Django编写的本地图书馆网站”)。</li>
+ <li>在Add .gitignore 选择列表中,选择 <strong>Python</strong>。</li>
+ <li>在添加许可证选择列表中,选择您想要的许可证。</li>
+ <li>选中使用自述文件初始化此储存库(<strong>Initialize this repository with a README)</strong>。</li>
+ </ul>
+ </li>
+ <li>点击 <strong>Create repository</strong>.</li>
+ <li>点击新仓库页面上的绿色 “克隆或下载”<strong> </strong>(<strong>Clone or download</strong>)按钮 。</li>
+ <li>从显示的对话框中的文本字段中复制URL值(它应该类似于: <strong>https://github.com/<em>&lt;your_git_user_id&gt;</em>/django_local_library.git</strong>)。</li>
+</ol>
+
+<p>现在创建了储存库(“repo”),我们将要在本地计算机上克隆它:</p>
+
+<ol>
+ <li>为您的本地计算机安装 git(您可以在<a href="https://git-scm.com/downloads">此处</a>找到不同平台的版本)。</li>
+ <li>打开命令提示符/终端,并使用您在上面复制的 URL 克隆储存库:
+ <pre class="brush: bash notranslate">git clone https://github.com/<strong><em>&lt;your_git_user_id&gt;</em></strong>/django_local_library.git
+</pre>
+ 这将在当前目录下方创建储存库。</li>
+ <li>切换目录,到新的仓库。
+ <pre class="brush: bash notranslate">cd django_local_library</pre>
+ </li>
+</ol>
+
+<p>最后一步是复制你的应用程序,然后使用 git ,将文件添加到你的仓库:</p>
+
+<ol>
+ <li>将您的 Django 应用程序,复制到此文件夹(与 <strong>manage.py</strong> 级别相同的、和以下级别的所有文件,而<strong>不是</strong>包含 locallibrary 文件夹的文件)。</li>
+ <li>打开<strong>.gitignore</strong>文件,将以下几行复制到其底部,然后保存(此文件用于标识默认情况下,不应上传到 git 的文件)。
+ <pre class="notranslate"># Text backup files
+*.bak
+
+#Database
+*.sqlite3</pre>
+ </li>
+ <li>打开命令提示符/终端,并使用<code>add</code>命令,将所有文件添加到 git。
+ <pre class="brush: bash notranslate">git add -A
+</pre>
+ </li>
+ <li>使用 status 命令,检查要添加的所有文件是否正确(您希望包含源文件,而不是二进制文件,临时文件等)。它应该看起来有点像下面的列表。
+ <pre class="notranslate">&gt; git status
+On branch master
+Your branch is up-to-date with 'origin/master'.
+Changes to be committed:
+  (use "git reset HEAD &lt;file&gt;..." to unstage)
+
+        modified:   .gitignore
+        new file:   catalog/__init__.py
+ ...
+        new file:   catalog/migrations/0001_initial.py
+ ...
+        new file:   templates/registration/password_reset_form.html</pre>
+ </li>
+ <li>如果您满意,请将文件提交到本地储存库:
+ <pre class="brush: bash notranslate">git commit -m "First version of application moved into github"</pre>
+ </li>
+ <li>然后使用以下内容,将本地储存库同步到 Github 网站:
+ <pre class="notranslate">git push origin master</pre>
+ </li>
+</ol>
+
+<p>完成此操作后,您应该可以返回创建储存库的 Github上的页面,刷新页面,并看到您的整个应用程序已经上传。使用此添加/提交/推送循环,您可以在文件更改时,继续更新储存库。</p>
+
+<div class="note">
+<p><strong>提示:</strong> 这是备份您的“vanilla”项目的一个好时机 - 虽然我们将在以下部分中,进行的一些更改,可能对有些人在任何平台(或开发)上的部署有用,对其他人可能没有用。</p>
+
+<p>执行此操作的最佳方法,是使用 git 来管理您的修订。使用 git,您不仅可以回到特定的旧版本,而且可以在生产变更的单独“分支”中进行维护,并选择在生产和开发分支之间移动的任何更改。<a href="https://help.github.com/articles/good-resources-for-learning-git-and-github/">学习 Git</a> 非常值得,但超出了本主题的范围。</p>
+
+<p>最简单的方法是将文件复制到另一个位置。使用最符合您对 git 了解的方法!</p>
+</div>
+
+<h3 id="更新_Heroku_的应用程序">更新 Heroku 的应用程序</h3>
+
+<p>本节介绍了您需要对 LocalLibrary 应用程序进行的更改,以使其在Heroku上运行。虽然 Heroku 的<a href="https://devcenter.heroku.com/articles/getting-started-with-python#introduction">在 Heroku 使用 Django 入门教程</a>,假设您将使用 Heroku 客户端,来运行您的本地开发环境,但我们的更改,与现有的 Django 开发服务器,以及我们已经学习的工作方式兼容。</p>
+
+<h4 id="Procfile">Procfile</h4>
+
+<p>在 GitHub 储存库的根目录中,创建文件<code>Procfile</code>(无扩展名),以声明应用程序的进程类型和入口点。将以下文本复制到其中:</p>
+
+<pre class="notranslate">web: gunicorn locallibrary.wsgi --log-file -</pre>
+
+<p>“<code>web:</code>”告诉 Heroku ,这是一个 web dyno,可以发送 HTTP 流量。在这个 dyno 中启动的进程,是 gunicorn,这是 Heruko 推荐的一种流行的 Web 应用程序服务器。我们使用模块 <code>locallibrary.wsgi</code>(使用我们的应用程序框架创建:<strong>/locallibrary/wsgi.py </strong>)中的配置信息启动 Gunicorn。</p>
+
+<h4 id="Gunicorn">Gunicorn</h4>
+
+<p><a href="http://gunicorn.org/">Gunicorn</a> 是推荐的 HTTP 服务器,用于 Heroku 上的 Django(如上面的 Procfile 中所述)。它是一个用于 WSGI 应用程序的纯 Python HTTP 服务器,可以在一个 dyno 中,运行多个 Python 并发进程(有关更多信息,请参阅<a href="https://devcenter.heroku.com/articles/python-gunicorn">使用 Gunicorn 部署 Python 应用程序</a>)。</p>
+
+<p>虽然在开发期间,我们不需要 Gunicorn 为我们的 LocalLibrary 应用程序提供服务,但我们将安装它,以便它成为我们在远程服务器上设置 Heroku 的 <a href="#requirements">requirements</a> 的一部分。</p>
+
+<p>使用 pip(我们在<a href="/zh-CN/docs/Learn/Server-side/Django/development_environment">设置开发环境</a>时安装)在命令行上,将 Gunicorn 安装到本地:</p>
+
+<pre class="brush: bash notranslate">pip3 install gunicorn
+</pre>
+
+<h4 id="数据库配置">数据库配置</h4>
+
+<p>我们不能在 Heroku 上使用默认的 SQLite 数据库,因为它是基于文件的,并且每次应用程序重新启动时,都会从暂时的文件系统中删除它(通常每天一次,每次应用程序或其配置变量被更改时)。</p>
+
+<p>处理这种情况的 Heroku 机制,是使用<a href="https://elements.heroku.com/addons#data-stores">数据库加载项</a>,并使用来自加载项设置的环境<a href="https://devcenter.heroku.com/articles/config-vars">配置变量</a>的信息,来配置 Web 应用程序。有很多数据库选项,但我们将使用 Heroku postgres 数据库的<a href="https://devcenter.heroku.com/articles/heroku-postgres-plans#plan-tiers">爱好者等级</a>,因为它是免费的,被 Django 所支持,并在使用免费的爱好者 dyno 计划等级时,会自动添加到新的 Heroku 应用程序。</p>
+
+<p>使用名为<code>DATABASE_URL</code>的配置变量,将数据库连接信息提供给 Web dyno。Heroku 建议开发人员使用 <a href="https://warehouse.python.org/project/dj-database-url/">dj-database-url </a>套件包,以解析<code>DATABASE_URL</code>环境变量,并自动将其转换为 Django 所需的配置格式,而不是将此信息硬编码到 Django 中。除了安装 dj-database-url 套件包之外,我们还需要安装<a href="http://initd.org/psycopg/">psycopg2</a>,因为 Django 需要它与 Postgres 数据库进行交互。</p>
+
+<h5 id="dj-database-url_Django_database_configuration_from_environment_variable">dj-database-url (Django database configuration from environment variable)</h5>
+
+<p>在本地安装 dj-database-url,使其成为我们在远程服务器上设置 Heroku 的 <a href="#requirements">requirements</a> 的一部分:</p>
+
+<pre class="notranslate">$ pip3 install dj-database-url
+</pre>
+
+<h5 id="settings.py">settings.py</h5>
+
+<p>打开<strong>/locallibrary/settings.py</strong>,并将以下配置复制到文件的底部:</p>
+
+<pre class="notranslate"># Heroku: Update database configuration from $DATABASE_URL.
+import dj_database_url
+db_from_env = dj_database_url.config(conn_max_age=500)
+DATABASES['default'].update(db_from_env)</pre>
+
+<div class="note">
+<p><strong>注意:</strong></p>
+
+<ul>
+ <li>我们仍然会在开发期间使用SQLite,因为我们的开发计算机上不会设置<code>DATABASE_URL</code>环境变量。</li>
+ <li><code>conn_max_age=500</code>的值使连接持久,这比在每个请求周期重新创建连接更有效。但是,这是可选的,如果需要可以删除。</li>
+</ul>
+</div>
+
+<h5 id="psycopg2_Python_Postgres_database_support">psycopg2 (Python Postgres database support)</h5>
+
+<p>Django 需要 psycopg2 来处理 Postgres 数据库,你需要将它添加到<a href="#requirements">requirements.txt </a>中,以便 Heroku 在远程服务器上进行设置(如下面的 requirements 部分所述)。</p>
+
+<p>Django 默认会在本地使用我们的 SQLite 数据库,因为我们的本地环境中,没有设置<code>DATABASE_URL</code>环境变量。如果您想完全切换到Postgres ,并使用我们的 Heroku 免费等级数据库,进行开发和生产,那么您可以这么做。例如,要在基于 Linux 的系统上,本地安装psycopg2 及其依赖项,您将使用以下 bash / terminal 命令:</p>
+
+<pre class="brush: bash notranslate"><code>sudo apt-get install python-pip python-dev libpq-dev postgresql postgresql-contrib</code>
+pip3 install psycopg2
+</pre>
+
+<p>有关其他平台的安装说明,请访问 <a href="http://initd.org/psycopg/docs/install.html">psycopg2 </a>网站。</p>
+
+<p>但是,您不需要这样做 - 您不需要在本地计算机上激活 PostGreSQL,只要将其作为要求(requirement)提供给 Heroku,请参阅<code>requirements.txt</code>(见下文)。</p>
+
+<h4 id="在生产环境中提供静态文件">在生产环境中提供静态文件</h4>
+
+<p>在开发过程中,我们使用 Django 和 Django 开发 Web 服务器,来提供静态文件(CSS,JavaScript 等)。在生产环境中,我们通常提供来自内容传送网络(CDN)或 Web 服务器的静态文件。</p>
+
+<div class="note">
+<p><strong>注意:</strong> 通过 Django/web 应用程序提供静态文件是低效的,因为请求必须通过不必要的附加代码(Django),而不是由 Web 服务器或完全独立的 CDN 直接处理。虽然这对于开发期间的本地使用无关紧要,但如果我们在生产环境中使用相同的方法,则会对性能产生重大影响。</p>
+</div>
+
+<p>为了便于将静态文件与 Django Web 应用程序分开托管,Django 提供了 collectstatic 工具,来收集这些文件以进行部署(有一个设置变量,用于定义在运行 collectstatic 时,应该收集文件的位置)。 Django 模板是指相对于设置变量(<code>STATIC_URL</code>)的静态文件的托管位置,因此如果将静态文件移动到另一个主机/服务器,则可以更改此位置。</p>
+
+<p>相关的设置变量是:</p>
+
+<ul>
+ <li><code>STATIC_URL</code>:  这是将提供静态文件的基本 URL 位置,例如,在CDN上。这用于在我们的基本模板中访问的静态模板变量(请参阅 <a href="/zh-CN/docs/Learn/Server-side/Django/Home_page">Django 教程 5:创建我们的主页</a>)。</li>
+ <li><code>STATIC_ROOT</code>: 这是 Django 的 “collectstatic” 工具将收集模板中引用的任何静态文件的目录的绝对路径。收集完成后,可以将这些文件,作为一个组上载到托管文件的任何位置。</li>
+ <li><code>STATICFILES_DIRS</code>: 这列出了 Django 的 collectstatic 工具应该搜索静态文件的其他目录。</li>
+</ul>
+
+<h5 id="settings.py_2">settings.py</h5>
+
+<p>打开<strong>/locallibrary/settings.py</strong>,并将以下配置,复制到文件的底部。 <code>BASE_DIR </code>应该已经在您的文件中定义了(<code>STATIC_URL</code>可能已经在文件创建时已经定义。虽然它不会造成任何伤害,但您也可以删除重复的先前引用)。</p>
+
+<pre class="notranslate"># Static files (CSS, JavaScript, Images)
+# https://docs.djangoproject.com/en/2.0/howto/static-files/
+
+# The absolute path to the directory where collectstatic will collect static files for deployment.
+STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
+
+# The URL to use when referring to static files (where they will be served from)
+STATIC_URL = '/static/'
+</pre>
+
+<p>我们实际上,将使用名为 <a href="https://warehouse.python.org/project/whitenoise/">WhiteNoise</a> 的库来提供文件,我们将在下一节中安装和配置。</p>
+
+<p>有关更多信息,请参阅 <a href="https://devcenter.heroku.com/articles/django-assets">Django和静态资产</a>(Heroku 文档)。<br>
+ <br>
+ Whitenoise</p>
+
+<p>有许多方法可以在生产环境中提供静态文件(我们在前面的部分中看到了相关的 Django 设置)。 Heroku 建议在生产环境中使用 <a href="https://warehouse.python.org/project/whitenoise/">WhiteNoise</a> 项目,直接从 Gunicorn 提供静态资产。</p>
+
+<div class="note">
+<p><strong>注意: </strong>Heroku 会在上传您的应用程序后,自动调用collectstatic 并准备静态文件,以供 WhiteNoise 使用。查看 <a href="https://warehouse.python.org/project/whitenoise/">WhiteNoise</a> 文档,了解其工作原理以及实现,为什么是提供这些文件的相对有效方法。</p>
+</div>
+
+<p>设置 WhiteNoise 以便在项目中使用的步骤如下:</p>
+
+<h5 id="WhiteNoise">WhiteNoise</h5>
+
+<p>使用以下命令在本地安装 whitenoise:</p>
+
+<pre class="notranslate">$ pip3 install whitenoise
+</pre>
+
+<h5 id="settings.py_3">settings.py</h5>
+
+<p>要将 WhiteNoise 安装到您的 Django 应用程序中,请打开<strong>/locallibrary/settings.py</strong>,找到<code>MIDDLEWARE</code>设置,并在<code>SecurityMiddleware</code>正下方的列表顶部附近,添加<code>WhiteNoiseMiddleware</code>:</p>
+
+<pre class="notranslate">MIDDLEWARE = [
+    'django.middleware.security.SecurityMiddleware',
+ <strong>'whitenoise.middleware.WhiteNoiseMiddleware',</strong>
+    'django.contrib.sessions.middleware.SessionMiddleware',
+    'django.middleware.common.CommonMiddleware',
+    'django.middleware.csrf.CsrfViewMiddleware',
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
+    'django.contrib.messages.middleware.MessageMiddleware',
+    'django.middleware.clickjacking.XFrameOptionsMiddleware',
+]
+</pre>
+
+<p>这是可选的,您可以在提供静态文件时,减小它们的大小(这样更有效)。只需将以下内容添加到<strong>/locallibrary/settings.py</strong>的底部:</p>
+
+<pre class="notranslate"># Simplified static file serving.
+# https://warehouse.python.org/project/whitenoise/
+STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
+</pre>
+
+<h4 id="Requirements">Requirements</h4>
+
+<p>Web 应用程序的 Python requirements ,必须放在储存库根目录中的文件 <strong>requirements.txt</strong> 中。然后 Heroku 将在重建您的环境时,自动安装它们。您可以在命令行上,使用 pip 创建此文件(在 repo 根目录中,运行以下命令):</p>
+
+<pre class="brush: bash notranslate">pip3 freeze &gt; requirements.txt</pre>
+
+<p>安装上面所有不同的依赖项后,您的 <strong>requirements.txt</strong> 文件,应至少列出这些项目(尽管版本号可能不同)。请删除下面未列出的任何其他依赖项,除非您已为此应用程序明确添加它们。</p>
+
+<pre class="notranslate">dj-database-url==0.4.1
+Django==2.0
+gunicorn==19.6.0
+<strong>psycopg2==2.6.2</strong>
+whitenoise==3.2.2
+</pre>
+
+<div class="note">
+<p><strong>注意</strong>:确保存在类似上面的 <strong>psycopg2 </strong>的那一行!即使你没有在本地安装它,你仍然应该将它添加到<strong>requirements.txt</strong>。</p>
+</div>
+
+<h4 id="Runtime">Runtime</h4>
+
+<p><strong>runtime.txt </strong>文件(如果已定义)告诉 Heroku 使用哪种编程语言。在 repo 的根目录中,创建文件并添加以下文本:</p>
+
+<pre class="notranslate">python-3.6.4</pre>
+
+<div class="note">
+<p><strong>注意:</strong> Heroku 只支持少量的 <a href="https://devcenter.heroku.com/articles/python-support#supported-python-runtimes">Python 运行库</a>(在编写本文时,包括上面的那个)。 Heroku 将使用受支持的运行库,而不管此文件中指定的值。</p>
+</div>
+
+<h4 id="将更改保存到_Github_并重新测试">将更改保存到 Github 并重新测试</h4>
+
+<p>接下来,我们将所有更改保存到 Github。在终端(我们的存储库中的 whist)中,输入以下命令:</p>
+
+<pre class="brush: python notranslate">git add -A
+git commit -m "Added files and changes required for deployment to heroku"
+git push origin master</pre>
+
+<p>在我们继续之前,让我们在本地,再次测试网站,并确保它不受上述任何更改的影响。像往常一样运行开发 Web 服务器,然后检查站点,是否仍然按预期在浏览器上运行。</p>
+
+<pre class="brush: bash notranslate">python3 manage.py runserver</pre>
+
+<p>我们现在应该准备开始在 Heroku 上部署 LocalLibrary。</p>
+
+<h3 id="获取_Heroku_帐户">获取 Heroku 帐户</h3>
+
+<p>要开始使用Heroku,您首先需要创建一个帐户:</p>
+
+<ul>
+ <li>访问 <a href="https://www.heroku.com/">www.heroku.com</a> ,并单击免费注册按钮(<strong>SIGN UP FOR FREE)</strong>。</li>
+ <li>输入您的详细信息,然后按 <strong>CREATE FREE ACCOUNT</strong>。系统会要求您,检查帐户中是否有注册电子邮件。</li>
+ <li>单击注册电子邮件中的帐户激活链接。您将在网络浏览器上收回您的帐户。</li>
+ <li>输入您的密码,然后单击 <strong>SET PASSWORD AND LOGIN</strong>。</li>
+ <li>然后,您将登录并进入 Heroku 仪表板: <a href="https://dashboard.heroku.com/apps">https://dashboard.heroku.com/apps</a>.</li>
+</ul>
+
+<h3 id="安装客户端">安装客户端</h3>
+
+<p>按照 <a href="https://devcenter.heroku.com/articles/getting-started-with-python#set-up">Heroku 上的说明</a>,下载并安装 Heroku 客户端。</p>
+
+<p>安装客户端后,您将能够运行命令。例如,要获得客户端的帮助:</p>
+
+<pre class="brush: bash notranslate">heroku help
+</pre>
+
+<h3 id="创建并上传网站">创建并上传网站</h3>
+
+<p>要创建应用程序,我们在储存库的根目录中,运行“create”命令。这将在我们的本地 git 环境中,创建一个名为 heroku 的 git remote(“指向远程储存库的指标”)。</p>
+
+<pre class="brush: bash notranslate">heroku create</pre>
+
+<div class="note">
+<p><strong>注意:</strong> 如果您愿意,可以通过在“创建”之后指定值来命名远程。如果你不这样做,你会得到一个随机的名字。该名称用于默认URL。</p>
+</div>
+
+<p>然后我们可以将应用程序,推送到 Heroku 储存库,如下所示。这将上传应用程序,将其打包到 dyno 中,运行 collectstatic,然后启动该站点。</p>
+
+<pre class="brush: bash notranslate">git push heroku master</pre>
+
+<p>如果我们很幸运,该应用程序现在在网站上“运行”,但它将无法正常工作,因为我们尚未设置数据库表,以供我们的应用程序使用。为此,我们需要使用 heroku run命令,并启动 “<a href="https://devcenter.heroku.com/articles/deploying-python#one-off-dynos">one off dyno</a>” 来执行迁移操作。在终端中输入以下命令:</p>
+
+<pre class="brush: bash notranslate">heroku run python manage.py migrate</pre>
+
+<p>我们还需要能够添加书本和作者,所以我们再次使用一次性dyno,创建我们的管理超级用户:</p>
+
+<pre class="brush: bash notranslate">heroku run python manage.py createsuperuser</pre>
+
+<p>完成后,我们可以查看该网站。它应该有用,虽然它还没有任何书本。要打开浏览器访问新网站,请使用以下命令:</p>
+
+<pre class="brush: bash notranslate">heroku open</pre>
+
+<p>在管理站点中创建一些书本,并检查该站点是否按预期运行。</p>
+
+<h3 id="管理附加组件(插件)">管理附加组件(插件)</h3>
+
+<p>您可以使用 <code>heroku addons</code>命令,查看应用程序的附加组件。这将列出所有附加组件,以及它们的价格等级和状态。</p>
+
+<pre class="brush: bash notranslate">&gt;heroku addons
+
+Add-on Plan Price State
+───────────────────────────────────────── ───────── ───── ───────
+heroku-postgresql (postgresql-flat-26536) hobby-dev free created
+ └─ as DATABASE</pre>
+
+<p>在这里,我们看到我们只有一个附加组件,即 postgres SQL数据库。这是免费的,并且是在我们创建应用时,自动创建的。您可以使用以下命令,更详细地打开网页,以检查数据库附加组件(或任何其他附加组件):</p>
+
+<pre class="brush: bash notranslate">heroku addons:open heroku-postgresql
+</pre>
+
+<p>其他命令允许您创建,销毁,升级和降级附加组件(使用类似的语法打开)。有关更多信息,请参阅<a href="https://devcenter.heroku.com/articles/managing-add-ons">管理附加组件</a>(Heroku 文档)。</p>
+
+<h3 id="设定配置变量">设定配置变量</h3>
+
+<p>您可以使用 <code>heroku config</code>命令,检查站点的配置变量。下面你可以看到,我们只有一个变量,<code>DATABASE_URL</code>用于配置我们的数据库。</p>
+
+<pre class="brush: bash notranslate">&gt;heroku config
+
+=== locallibrary Config Vars
+DATABASE_URL: postgres://uzfnbcyxidzgrl:j2jkUFDF6OGGqxkgg7Hk3ilbZI@ec2-54-243-201-144.compute-1.amazonaws.com:5432/dbftm4qgh3kda3</pre>
+
+<p>如果您回想起来<strong>准备发布网站</strong>的部分,我们必须为<code>DJANGO_SECRET_KEY</code> 和 <code>DJANGO_DEBUG</code>设置环境变量。我们现在就这样做。</p>
+
+<div class="note">
+<p><strong>注意:</strong> 密钥需要真正的保密!生成新密钥的一种方法,是创建一个新的 Django 项目(<code>django-admin startproject someprojectname</code>),然后从 <strong>settings.py </strong>中,获取为您生成的密钥。</p>
+</div>
+
+<p>我们使用 <code>config:set</code>命令,设置<code>DJANGO_SECRET_KEY</code>(如下所示)。记得使用自己的密钥!</p>
+
+<pre class="brush: bash notranslate">&gt;heroku config:set DJANGO_SECRET_KEY=eu09(ilk6@4sfdofb=b_2ht@vad*$ehh9-)3u_83+y%(+phh&amp;=
+
+Setting DJANGO_SECRET_KEY and restarting locallibrary... done, v7
+DJANGO_SECRET_KEY: eu09(ilk6@4sfdofb=b_2ht@vad*$ehh9-)3u_83+y%(+phh
+</pre>
+
+<p>我们以同样的方式设置<code>DJANGO_DEBUG</code>:</p>
+
+<pre class="brush: bash notranslate">&gt;heroku config:set <code>DJANGO_DEBUG=''
+
+Setting DJANGO_DEBUG and restarting locallibrary... done, v8</code></pre>
+
+<p>如果您现在访问该站点,您将收到“错误请求”(Bad request)错误,因为如果您有 <code>DEBUG=False</code>(作为安全措施),则需要<a href="https://docs.djangoproject.com/en/2.0/ref/settings/#allowed-hosts">ALLOWED_HOSTS</a> 设置。打开 <strong>/locallibrary/settings.py</strong>,并更改<code>ALLOWED_HOSTS</code>设置,以包含您的基本应用程序 URL(例如'locallibrary1234.herokuapp.com'),以及您通常在本地开发服务器上使用的 URL。</p>
+
+<pre class="brush: python notranslate">ALLOWED_HOSTS = ['&lt;your app URL without the https:// prefix&gt;.herokuapp.com','127.0.0.1']
+# For example:
+# ALLOWED_HOSTS = ['fathomless-scrubland-30645.herokuapp.com','127.0.0.1']
+</pre>
+
+<p>然后保存您的设置,并将它们提交到您的 Github 仓库和 Heroku:</p>
+
+<pre class="brush: bash notranslate">git add -A
+git commit -m 'Update ALLOWED_HOSTS with site and development server URL'
+git push origin master
+git push heroku master</pre>
+
+<div class="note">
+<p>完成 Heroku 的站点更新后,输入一个不存在的 URL(例如,<strong>/catalog/doesnotexist/</strong>)。以前这会显示一个详细的调试页面,但现在,您应该只看到一个简单的“未找到”页面。</p>
+</div>
+
+<h3 id="除错调试">除错调试</h3>
+
+<p>Heroku客户端提供了一些调试工具:</p>
+
+<pre class="brush: bash notranslate">heroku logs # Show current logs
+heroku logs --tail # Show current logs and keep updating with any new results
+heroku config:set DEBUG_COLLECTSTATIC=1 # Add additional logging for collectstatic (this tool is run automatically during a build)
+heroku ps #Display dyno status
+</pre>
+
+<p>如果您需要比这些更多的信息,您将需要开始研究 <a href="https://docs.djangoproject.com/en/2.0/topics/logging/">Django Logging</a>。</p>
+
+<h2 id="总结"><strong><span style='font-family: x-locale-heading-primary,zillaslab,Palatino,"Palatino Linotype",x-locale-heading-secondary,serif; font-size: 2.5rem;'>总结</span></strong></h2>
+
+<p>本教程讲述如何在生产环境中配置Django应用,也是本系列Django教程的结尾。我们希望你觉得教程有用。你可以在Github上取得一个完全可工作版本的<a href="https://github.com/mdn/django-locallibrary-tutorial">源码(用力点击此处)</a>。</p>
+
+<p>下一步是阅读我们此前的一些文章,然后完成评估任务。</p>
+
+<h2 id="也可以参考">也可以参考</h2>
+
+<ul>
+ <li><a href="https://docs.djangoproject.com/en/2.0/howto/deployment/">Deploying Django</a> (Django 文档)
+
+ <ul>
+ <li><a href="https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/">Deployment checklist</a> (Django 文档)</li>
+ <li><a href="https://docs.djangoproject.com/en/2.0/howto/static-files/deployment/">Deploying static files</a> (Django 文档)</li>
+ <li><a href="https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/">How to deploy with WSGI</a> (Django 文档)</li>
+ <li><a href="https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/modwsgi/">How to use Django with Apache and mod_wsgi</a> (Django 文档)</li>
+ <li><a href="https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/gunicorn/">How to use Django with Gunicorn</a> (Django 文档)</li>
+ </ul>
+ </li>
+ <li>Heroku
+ <ul>
+ <li><a href="https://devcenter.heroku.com/articles/django-app-configuration">Configuring Django apps for Heroku</a> (Heroku 文档)</li>
+ <li><a href="https://devcenter.heroku.com/articles/getting-started-with-python#introduction">Getting Started on Heroku with Django</a> (Heroku 文档)</li>
+ <li><a href="https://devcenter.heroku.com/articles/django-assets">Django and Static Assets</a> (Heroku 文档)</li>
+ <li><a href="https://devcenter.heroku.com/articles/python-concurrency-and-database-connections">Concurrency and Database Connections in Django</a> (Heroku 文档)</li>
+ <li><a href="https://devcenter.heroku.com/articles/how-heroku-works">How Heroku works</a> (Heroku 文档)</li>
+ <li><a href="https://devcenter.heroku.com/articles/dynos">Dynos and the Dyno Manager</a> (Heroku 文档)</li>
+ <li><a href="https://devcenter.heroku.com/articles/config-vars">Configuration and Config Vars</a> (Heroku 文档)</li>
+ <li><a href="https://devcenter.heroku.com/articles/limits">Limits</a> (Heroku 文档)</li>
+ <li><a href="https://devcenter.heroku.com/articles/python-gunicorn">Deploying Python applications with Gunicorn</a> (Heroku 文档)</li>
+ <li><a href="https://devcenter.heroku.com/articles/deploying-python">Deploying Python and Django apps on Heroku</a> (Heroku 文档)</li>
+ <li><a href="https://devcenter.heroku.com/search?q=django">Other Heroku Django docs</a></li>
+ </ul>
+ </li>
+ <li>Digital Ocean
+ <ul>
+ <li><a href="https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-uwsgi-and-nginx-on-ubuntu-16-04">How To Serve Django Applications with uWSGI and Nginx on Ubuntu 16.04</a></li>
+ <li><a href="https://www.digitalocean.com/community/tutorials?q=django">Other Digital Ocean Django community docs</a></li>
+ </ul>
+ </li>
+</ul>
+
+<p>{{PreviousMenuNext("Learn/Server-side/Django/Testing", "Learn/Server-side/Django/web_application_security", "Learn/Server-side/Django")}}</p>
+
+
+
+<h2 id="本教程文章">本教程文章</h2>
+
+<ul>
+ <li><a href="/en-US/docs/Learn/Server-side/Django/Introduction">Django introduction</a></li>
+ <li><a href="/en-US/docs/Learn/Server-side/Django/development_environment">Setting up a Django development environment</a></li>
+ <li><a href="/en-US/docs/Learn/Server-side/Django/Tutorial_local_library_website">Django Tutorial: The Local Library website</a></li>
+ <li><a href="/en-US/docs/Learn/Server-side/Django/skeleton_website">Django Tutorial Part 2: Creating a skeleton website</a></li>
+ <li><a href="/en-US/docs/Learn/Server-side/Django/Models">Django Tutorial Part 3: Using models</a></li>
+ <li><a href="/en-US/docs/Learn/Server-side/Django/Admin_site">Django Tutorial Part 4: Django admin site</a></li>
+ <li><a href="/en-US/docs/Learn/Server-side/Django/Home_page">Django Tutorial Part 5: Creating our home page</a></li>
+ <li><a href="/en-US/docs/Learn/Server-side/Django/Generic_views">Django Tutorial Part 6: Generic list and detail views</a></li>
+ <li><a href="/en-US/docs/Learn/Server-side/Django/Sessions">Django Tutorial Part 7: Sessions framework</a></li>
+ <li><a href="/en-US/docs/Learn/Server-side/Django/Authentication">Django Tutorial Part 8: User authentication and permissions</a></li>
+ <li><a href="/en-US/docs/Learn/Server-side/Django/Forms">Django Tutorial Part 9: Working with forms</a></li>
+ <li><a href="/en-US/docs/Learn/Server-side/Django/Testing">Django Tutorial Part 10: Testing a Django web application</a></li>
+ <li><a href="/en-US/docs/Learn/Server-side/Django/Deployment">Django Tutorial Part 11: Deploying Django to production</a></li>
+ <li><a href="/en-US/docs/Learn/Server-side/Django/web_application_security">Django web application security</a></li>
+ <li><a href="/en-US/docs/Learn/Server-side/Django/django_assessment_blog">DIY Django mini blog</a></li>
+</ul>