aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/conflicting/learn/server-side/django/index.html
blob: 86ecd5bb6cb27c5454c81b791e26a326c51c6a7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
---
title: Python
slug: conflicting/Learn/Server-side/Django
tags:
  - Python
  - Services
translation_of: Learn/Server-side/Django
translation_of_original: Python
original_slug: Python
---
<p><a class="external" href="http://www.python.org">Python</a> 是一款直译式脚本语言,支持包括 Linux、Mac OS X 和 Microsoft Windows 在内的多种平台。</p>

<h2 id="Learning_Python" name="Learning_Python">学习 Python</h2>

<h3 id="免费的电子书">免费的电子书</h3>

<p> 如果你是个初学者,可以考虑看看 <a class="external" href="http://www.diveintopython.net/toc/index.html">Dive Into Python</a> 。虽然它<span id="result_box" lang="zh-CN"><span title="如果是初學Python,可以考慮看Dive Into Python,雖然他最後是更新的時間是2004年,但依然是一部免費而且很棒的教程。">最后更新的时间是2004年,但依然是一部免费而且很棒的教程。</span></span> <span id="result_box" lang="zh-CN"><span title="它含括了幾乎所有Python 的基本元素,還有一些平常使用Python 可以執行什麼任務,像是網頁的請求,檔案的處理。">它含括了几乎所有Python 的基本元素,还有一些平常使用 Python 可以执行什么任务,像是对 Web 请求和文件的处理。</span><span title="如果對於Python 基礎已經基礎的概念,就可以參考">如果对于 Python 已经有了基本的概念,就可以考虑看看</span></span> <a class="external" href="http://gnosis.cx/TPiP/">Text Processing In Python</a>,这本书对于 Python 有着更进阶的介绍。</p>

<p>还有其他免费的电子书和在线资源可供参考:</p>

<ul style="margin-left: 40px;">
 <li><a class="external" href="http://docs.python.org/tutorial/index.html" title="http://docs.python.org/tutorial/index.html">Python 教程</a>(托管于 <a href="http://docs.python.org" title="http://docs.python.org">docs.python.org</a>&gt;&gt; 教程已被网友翻译成中文版:<a href="http://www.pythondoc.com/">http://www.pythondoc.com/</a> <strong><span style="color: #ff0000;">推荐</span></strong></li>
 <li><a href="http://en.wikibooks.org/wiki/Non-Programmer%27s_Tutorial_for_Python_2.6" title="http://en.wikibooks.org/wiki/Non-Programmer%27s_Tutorial_for_Python_2.6">为非程序员编写的 Python 2.6 教程</a>(托管于 <a href="http://en.wikibooks.org/wiki/Main_Page" title="http://en.wikibooks.org/wiki/Main_Page">Wikibooks</a></li>
 <li><a href="http://www.greenteapress.com/thinkpython/" title="http://www.greenteapress.com/thinkpython/">Think Python</a>: How to Think Like a Computer Scientist by Allen B. Downey (free <a href="http://www.greenteapress.com/thinkpython/thinkpython.pdf" title="http://www.greenteapress.com/thinkpython/thinkpython.pdf">PDF</a> &amp; <a href="http://www.greenteapress.com/thinkpython/html/index.html" title="http://www.greenteapress.com/thinkpython/html/index.html">HTML</a> versions).
  <ul>
   <li><a href="http://greenteapress.com/complexity/index.html" title="http://greenteapress.com/complexity/index.html">Think Complexity</a> by Allen B. Downey "picks up where Think Python leaves off" (free <a href="http://greenteapress.com/complexity/thinkcomplexity.pdf" title="http://greenteapress.com/complexity/thinkcomplexity.pdf">PDF</a> &amp; <a href="http://greenteapress.com/complexity/html/index.html" title="http://greenteapress.com/complexity/html/index.html">HTML</a> versions)</li>
  </ul>
 </li>
 <li><a href="http://learnpythonthehardway.org" title="http://learnpythonthehardway.org">Learn Python The Hard Way</a> by Zed Shaw (<a href="http://learnpythonthehardway.org/book/" title="http://learnpythonthehardway.org/book/">免费的 HTML 版)</a></li>
 <li><a href="http://www.itmaybeahack.com/book/python-2.6/html/index.html" title="http://www.itmaybeahack.com/book/python-2.6/html/index.html">Building Skills in Python</a> by Steven F. Lott (<a href="http://www.itmaybeahack.com/book/python-2.6/latex/BuildingSkillsinPython.pdf" title="http://www.itmaybeahack.com/book/python-2.6/latex/BuildingSkillsinPython.pdf">也有 PDF 版</a></li>
</ul>

<p><em>译者注:如果有发现其他中文教程,欢迎编写本页来分享</em></p>

<p>当你对这款语言有了基础的认识后, <a href="http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html" title="http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html">Code Like a Pythonista: Idiomatic Python</a> 将帮你了解 Python 的一些特别之处,以及和其他语言的区别。</p>

<h3 id="免费在线课程">免费在线课程</h3>

<ul style="margin-left: 40px;">
 <li><a href="https://developers.google.com/edu/python/" title="http://code.google.com/edu/languages/google-python-class/">Google's Python Class</a></li>
 <li>Learnstreet's Free <a href="http://www.learnstreet.com/lessons/languages/python" title="http://www.learnstreet.com/lessons/languages/python">Python Courses and Videos</a></li>
 <li><a href="http://www.codecademy.com/tracks/python" title="http://www.codecademy.com/tracks/python">Python</a> at Codecademy</li>
 <li><a href="http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-189-a-gentle-introduction-to-programming-using-python-january-iap-2008/" title="http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-189-a-gentle-introduction-to-programming-using-python-january-iap-2008/">A Gentle Introduction to Programming Using Python</a> at MIT</li>
 <li><a href="http://www.fireboxtraining.com" title="http://www.fireboxtraining.com">Firebox Training's</a> <a href="http://www.fireboxtraining.com/blog/python-tutorials/" title="http://www.fireboxtraining.com/blog/python-tutorials/">Free Python course video tutorial blog</a></li>
</ul>

<h2 id="Python_in_Mozilla" name="Python_in_Mozilla">Python 也用在了基于 Mozilla 的应用程序中</h2>

<p><a href="/en-US/docs/XPCOM" title="XPCOM">XPCOM</a> 在 Mozilla 中用于支持跨语言通信(inter-language communication)。它仅原生支持 C++ &lt;-&gt; JavaScript 的交流。 <a href="/en-US/docs/PyXPCOM" title="PyXPCOM">Python 的 XPCOM 组件</a>(也叫做 PyXPCOM)是将 Python 和 Mozilla 粘合在一块的低级别胶水(the low-level glue),使得用 JavaScript 或 C++ 编写的 XPCOM 组件既可以通过 Python 使用,反之亦然。PyXPCOM <strong>并不</strong>默认包含在 Firefox 构建版本中,因此你须要使用第三方构建版本或自己构建一个版本来使用它。PyXPCOM中最知名的消费者是<a href="https://www.activestate.com/komodo-ide">Komodo</a>系列的产品。 </p>

<p>从Mozilla 1.9版本开始就已经支持 (<a href="/en-US/docs/PyDOM" title="PyDOM">PyDOM</a>) 。 这也让<a href="/en-US/docs/Chrome" title="Chrome">chrome</a> 的XUL 和 HTML 作者在他们的 &lt;script&gt; 标签中使用python(再一次声明,官方版本的Firefox和Thunderbird版本还不支持)。</p>

<h2 id="Mozilla中基于Python的开发者工具">Mozilla中基于Python的开发者工具</h2>

<p>Python已经被众多Mozilla开发者应用于大量的app和框架中。更多信息请参考<a href="/en-US/docs/Python_Environment_and_Tools_for_Mozilla" title="Python_Environment_and_Tools_for_Mozilla">Python Environment and Tools for Mozilla</a>.</p>

<p>工具列表在这里: <a class="external" href="http://k0s.org/toolbox/?language=python">http://k0s.org/toolbox/?language=python</a></p>

<h2 id="Mozilla中Python的使用">Mozilla中Python的使用</h2>

<p>Mozilla有大量的基于python的框架,包括:</p>

<ul>
 <li>django for <a class="external" href="http://blog.mozilla.com/webdev/" title="http://blog.mozilla.com/webdev/">webdev</a></li>
 <li><a class="link-https" href="https://wiki.mozilla.org/Buildbot" title="https://wiki.mozilla.org/Buildbot">buildbot</a> 连续集成工具</li>
 <li>测试工具 <a href="/en-US/docs/Mozilla_automated_testing" title="Mozilla automated testing">test harnesses</a></li>
 <li><a class="link-https" href="https://wiki.mozilla.org/Auto-tools/Projects/Mozbase" title="https://wiki.mozilla.org/Auto-tools/Projects/MozBase">mozbase</a> : 测试工具,其他框架和工具的构建模块</li>
</ul>

<h2 id="Mozilla-Central的Python身影">Mozilla-Central的Python身影</h2>

<p>[参考网址://bugzilla.mozilla.org/show_bug.cgi?id=835553]</p>

<p>在Mozilla-Central很多的正式版本,测试版本以及其他的框架和工具都是使用的python</p>

<ul>
 <li><a href="http://mxr.mozilla.org/mozilla-central/source/python/" title="http://mxr.mozilla.org/mozilla-central/source/python/"><code>python/</code></a> 包含了通用的python代码,包括第三方镜像打包文件比如:pypi.python.org</li>
 <li><a href="http://mxr.mozilla.org/mozilla-central/source/testing/mozbase/" title="http://mxr.mozilla.org/mozilla-central/source/testing/mozbase/"><code>testing/mozbase/</code></a> 包含了<a href="https://wiki.mozilla.org/Auto-tools/Projects/Mozbase" title="https://wiki.mozilla.org/Auto-tools/Projects/Mozbase"><code>Mozbase</code></a> 中用于mozilla-central的镜像打包文件</li>
</ul>

<p>一个虚拟化环境(<a href="/en-US/docs/Python/Virtualenv" title="/en-US/docs/Python/Virtualenv">virtualenv</a>)包含在调用<code>$OBJDIR/_virtualenv</code> 版本的<a href="https://developer.mozilla.org/en-US/docs/Developer_Guide/Mozilla_build_FAQ#Build_configurations" title="https://developer.mozilla.org/en-US/docs/Developer_Guide/Mozilla_build_FAQ#Build_configurations"><code>objdir</code></a> 时 . 为了封装到虚拟环境中, 可编辑<a href="http://mxr.mozilla.org/mozilla-central/source/build/virtualenv_packages.txt" title="http://mxr.mozilla.org/mozilla-central/source/build/virtualenv/packages.txt">build/virtualenv_packages.txt </a>. 这里有安装好了的版本 <a href="http://mxr.mozilla.org/mozilla-central/source/build/virtualenv/populate_virtualenv.py" title="http://mxr.mozilla.org/mozilla-central/source/build/virtualenv/populate_virtualenv.py">build/virtualenv/populate_virtualenv.py</a> .</p>

<h2 id="Python的封装">Python的封装</h2>

<p>Python使用<a class="external" href="http://docs.python.org/distutils/index.html" title="http://docs.python.org/distutils/index.html">setup.py</a> 来记录元数据和python包(<a class="external" href="http://docs.python.org/tutorial/modules.html#packages" title="http://docs.python.org/tutorial/modules.html#packages">python packages</a>)的安装。运行 (e.g.) <code>python setup.py install</code> 将安装打包文件以及使<a class="external" href="http://docs.python.org/tutorial/modules.html#the-module-search-path" title="http://docs.python.org/tutorial/modules.html#the-module-search-path">python's import path</a>中的模块可用。对python 2.x来说, 有几种不同的分布式或安装式模块存在,<code><a class="external" href="http://docs.python.org/distutils/index.html" title="http://docs.python.org/distutils/index.html">distutils</a></code> 只在python标准库( <a class="external" href="http://docs.python.org/library/" title="http://docs.python.org/library/">python's standard library</a>)的分布式封装中可用, <code>distutils</code> 可以上传到python封装索引<a class="external" href="http://pypi.python.org/pypi" title="http://pypi.python.org/pypi">python package index</a> 并且安装python包。详情请参阅<a class="external" href="http://docs.python.org/distutils/index.html" title="http://docs.python.org/distutils/index.html">Python documentation on <code>distutils</code></a></p>

<p>当 <code>distutils</code> 已经被加入python标准库中后, 初始化工具 <a class="external" href="http://peak.telecommunity.com/DevCenter/setuptools" title="http://peak.telecommunity.com/DevCenter/setuptools">setuptools</a>是一个为封装和分发的第三方的特设标准。它几乎完全兼容<code>distutils</code>,但是却非常关键的使封装文件具有“依赖关系”<a class="external" href="http://peak.telecommunity.com/DevCenter/setuptools#declaring-dependencies" title="http://peak.telecommunity.com/DevCenter/setuptools#declaring-dependencies">include dependencies</a> 的能力,可以在<code>setup.py</code> 被调用的时候作为预置条件安装,同时也有了在开发者模式<a class="external" href="http://packages.python.org/distribute/setuptools.html#development-mode" title="http://packages.python.org/distribute/setuptools.html#development-mode">development mode</a>下安装python包的能力. 这使得文件能通过 <a class="external" href="http://docs.python.org/library/site.html" title="http://docs.python.org/library/site.html">.pth files</a>来编辑,这对于积极工作的人来说非常容易上手。 <code>setuptools</code> 也提供了一个通过 <a class="external" href="http://pypi.python.org/pypi" title="http://pypi.python.org/pypi">PyPI</a>来快速安装打包文件和依赖关系的脚本<code><a class="external" href="http://packages.python.org/distribute/easy_install.html" title="http://packages.python.org/distribute/easy_install.html">easy_install</a></code> 。比如安装 <a class="external" href="http://pyyaml.org/wiki/PyYAML" title="http://pyyaml.org/wiki/PyYAML">PyYAML</a>包,运行</p>

<pre>easy_install PyYAML
</pre>

<p>因为 <code>setuptools</code> 没有被包含在python中,你需要对其进行安装,你可以去到PyPI主页去下载<code>setuptools</code>i,然后解压,在目录下运行<code>python setup.py install</code> ,你也可以使用快速安装脚本<code><a class="external" href="http://peak.telecommunity.com/dist/ez_setup.py" title="http://peak.telecommunity.com/dist/ez_setup.py">ez_setup.py</a></code>来进行安装,你可以在拥有root权限或管理员权限的python环境中下载和安装,或者在 <a class="external" href="http://www.gnu.org/s/bash/" title="http://www.gnu.org/s/bash/">bash shell</a>中运行</p>

<pre>sudo python &lt;(curl http://peak.telecommunity.com/dist/ez_setup.py)
</pre>

<p><code>setuptools</code> 也提供了一个虚拟环境<a href="/en-US/docs/Python/Virtualenv" title="Virtualenv">virtualenv</a>, 所以如果你想使用虚拟环境来开发,你不需要全局安装<code>setuptools</code> ,<a class="external" href="http://packages.python.org/distribute/" title="http://packages.python.org/distribute/">distribute</a>是一个Mozilla大佬 <a class="external" href="http://ziade.org/" title="http://ziade.org/">Tarek Ziade</a> 在<code>setuptools</code> 的一个,它完全兼容<code>setuptools</code>,并修复了一些bug。</p>

<div class="note"><strong>注意:</strong> 非常建议你使用虚拟环境<a href="/en-US/docs/Python/Virtualenv" title="Virtualenv">virtualenv</a>来开发</div>

<p>python包索引<a class="external" href="http://pypi.python.org/pypi" title="http://pypi.python.org/pypi">Python Package Index (PyPI)</a> 是一个标准的python打包文件的分发点。如果你需要查找一些python的功能,这是一个很好的查询的地方。</p>

<p>参阅: <a class="external" href="http://k0s.org/portfolio/packaging.html">http://k0s.org/portfolio/packaging.html</a></p>

<h2 id="参阅:">参阅:</h2>

<ul>
 <li><a class="external" href="http://docs.services.mozilla.com/server-devguide/release.html" title="http://docs.services.mozilla.com/server-devguide/release.html">Releasing an application</a> (Mozilla Services documentation)</li>
 <li>http://pycheesecake.org/wiki/PythonTestingToolsTaxonomy</li>
 <li><a class="link-https" href="https://wiki.mozilla.org/Auto-tools/Python101">https://wiki.mozilla.org/Auto-tools/Python101</a></li>
 <li><a href="http://www.learnstreet.com/cg/simple/projects/python" title="http://www.learnstreet.com/cg/simple/projects/python">Python Projects </a>at Code Garage</li>
</ul>