ID English原文 中文翻译 最近翻译记录 状态 操作
0#翻译 Chapter 2: Getting Started 第二章:入门 翻译
3#翻译 Installing Django is a multi-step process, due to the multiple moving parts in modern Web development environments. 由于现代Web开发环境由多个部件组成,安装Django需要几个步骤。 翻译
4#翻译 In this chapter, we'll walk you through how to install the framework and its few dependencies. 这一章,我们将演示如何安装框架以及一些依赖关系。 翻译
6#翻译 Because Django is just Python code, it runs anywhere Python does including on some cell phones! 因为Django就是纯Python代码,它可以运行在任何Python可以运行的环境,甚至是手机上! 翻译
7#翻译 But this chapter just covers the common scenarios for Django installations. 但是这章只提及Django安装的通用脚本。 翻译
8#翻译 We'll assume youre installing it either on a desktop/laptop machine or a server. 我们假设你把它安装在桌面/笔记本电脑或服务器。 翻译
10#翻译 Later, in Chapter 12, we'll cover how to deploy Django to a production site. 往后,在第12章,我们将讨论如何部署Django到一个生产站点。 翻译
12#翻译 Installing Python Python 安装 翻译
14#翻译 Django itself is written purely in Python, so the first step in installing the framework is to make sure you have Python installed. Django本身是纯Python编写的,所以安装框架的第一步是确保你已经安装了Python。 翻译
16#翻译 Python Versions Python版本 翻译
18#翻译 The core Django framework works with any Python version from 2.3 to 2.6, inclusive. 核心Django框架可以工作在2.3至2.6(包括2.3和2.6)之间的任何Python版本。 翻译
19#翻译 Django's optional GIS (Geographic Information Systems) support requires Python 2.4 to 2.6. Django的可选GIS(地理信息系统)支持需要Python 2.4到2.6。 翻译
21#翻译 If you're not sure which version of Python to install and you have complete freedom over the decision, pick the latest one in the 2.x series: 如果你不确定要安装Python的什么版本,并且你完全拿不定主意的话,那就选2.x系列的最新版本吧。 翻译
22#翻译 version 2.6. 版本2.6。 翻译
23#翻译 Although Django works equally well with any version from 2.3 to 2.6, the later versions of Python have performance improvements and additional language features you might like to use in your applications. 虽然Django在2.3至2.6版之间的任意Python版本下都一样运行得很好,但是新版本的Python提供了一些你可能比较想应用在你的程序里的,更加丰富和额外的语言特性。 翻译
24#翻译 Plus, certain third-party Django add-ons that you might want to use might require a version newer than Python 2.3, so using a later version of Python keeps your options open. 另外,某些你可能要用到的Django第三方插件会要求比Python 2.3更新的版本,所以使用比较新的Python版本会让你有更多选择。 翻译
26#翻译 Django and Python 3.0 Django和 Python 3.0 翻译
28#翻译 At the time of writing, Python 3.0 had been released, but Django didn't yet support it. 在写作本书的时候,Python3.0已经发布,但Django暂时还不支持。 翻译
29#翻译 Python 3.0 introduced a substantial number of backwards-incompatible changes to the language itself, and, as a result, we expect most major Python libraries and frameworks, including Django, will take a few years to catch up. Python3.0这个语言本身引入了大量不向后兼容的改变,因此,我们预期大多数主要的Python库和框架将花几年才能衔接,包括Django。 翻译
31#翻译 If you're new to Python and are wondering whether to learn Python 2.x or Python 3.x, our advice is to stick with Python 2.x. 如果你是个Python新手并且正迷茫于到底是学习Python 2.x还是Python 3.x的话,我们建议你选择Python 2.x。 翻译
33#翻译 Installation 安装 翻译
35#翻译 If you're on Linux or Mac OS X, you probably have Python already installed. 如果使用的是 Linux 或 Mac OS X ,系统可能已经预装了 Python 。在命令提示符下 (或 OS X 的终端中) 输入 <literal>python</literal> ,如果看到如下信息,说明 Python 已经装好了: 翻译
36#翻译 Type <literal>python</literal> at a command prompt (or in Applications/Utilities/Terminal, in OS X). 在命令行窗口中输入<literal>python</literal> (或是在OS X的程序/工具/终端中)。 翻译
37#翻译 If you see something like this, then Python is installed: 如果你看到这样的信息,说明 python 已经安装好了. 翻译
40#翻译 Otherwise, you'll need to download and install Python. 否则, 你需要下载并安装Python. 翻译
41#翻译 It's fast and easy, and detailed instructions are available at <reference name="http://www.python.org/download/" refuri="http://www.python.org/download/">http://www.python.org/download/</reference> 它既快速又方便,而详细说明可参考<reference name="http://www.python.org/download/" refuri="http://www.python.org/download/">http://www.python.org/download/</reference> 翻译
43#翻译 Installing Django 安装 Django 翻译
45#翻译 At any given time, two distinct versions of Django are available to you: 任何时候,都有两个不同版本的Django供您选择。 翻译
46#翻译 the latest official release and the bleeding-edge trunk version. 最新的官方发行版和有风险的主干版本。 翻译
47#翻译 The version you decide to install depends on your priorities. 安装的版本取决于您的优先选择。 翻译
48#翻译 Do you want a stable and tested version of Django, or do you want a version containing the latest features, perhaps so you can contribute to Django itself, at the expense of stability? 你需要一个稳定的通过测试的Django,或是你想要包括最新功能的版本,也许你可对Django本身作贡献,而把稳定作为代价? 翻译
50#翻译 We'd recommend sticking with an official release, but it's important to know that the trunk development version exists, because you'll find it mentioned in the documentation and by members of the community. 我们推荐选定一个正式发布版本,但重要的是了解到主干开发版本的存在,因为在文档和社区成员中你会发现它被提到。 翻译
52#翻译 Installing an Official Release 安装官方发布版 翻译
54#翻译 Official releases have a version number, such as 1.0.3 or 1.1, and the latest one is always available at <reference name="http://www.djangoproject.com/download/" refuri="http://www.djangoproject.com/download/">http://www.djangoproject.com/download/</reference>. 官方发布的版本带有一个版本号,例如1.0.3或1.1,而最新版本总是可以在<reference name="http://www.djangoproject.com/download/" refuri="http://www.djangoproject.com/download/">http://www.djangoproject.com/download/</reference>找到。 翻译
56#翻译 If you're on a Linux distribution that includes a package of Django, it's a good idea to use the distributor's version. 如果您在用Linux系统,其中包括Django的包,使用默认的版本是个好主意。 翻译
57#翻译 That way, youll get security updates along with the rest of your system packages. 这样,你将会通过系统的包管理得到安全的升级。 翻译
59#翻译 If you don't have access to a prepackaged version, you can download and install the framework manually. 如果你的系统没有自带Django,你可以自己下载然后安装框架。 翻译
60#翻译 To do so, first download the tarball, which will be named something like <literal>Django-1.0.2-final.tar.gz</literal> . (It doesn't matter which local directory you download this file into; the installation process will put Django's files in the right place.) Then, unzip it and run <literal>setup.py install</literal> , as you do with most Python libraries. 首先,下载名字类似于<literal>Django-1.0.2-final.tar.gz</literal>压缩文件。(下载到哪里无所谓,安装程序会把Django文件放到正确的地方。)解压缩之后运行<literal>setup.py install</literal>,像操作大多数Python库一样。 翻译
62#翻译 Here's how that process looks on Unix systems: 以下是如何在Unix系统上安装的方法: 翻译
64#翻译 <literal>tar xzvf Django-1.0.2-final.tar.gz</literal> <literal>tar xzvf Django-*.tar.gz</literal> 。 翻译
66#翻译 <literal>cd Django-*</literal> <literal>cd Django-*</literal> 。 翻译
68#翻译 <literal>sudo python setup.py install</literal> <literal>sudo python setup.py install</literal> 。 翻译
70#翻译 On Windows, we recommend using 7-Zip (<reference name="http://www.djangoproject.com/r/7zip/" refuri="http://www.djangoproject.com/r/7zip/">http://www.djangoproject.com/r/7zip/</reference>) to unzip <literal>.tar.gz</literal> files. Windows系统上,推荐使用7-Zip(<reference name="http://www.djangoproject.com/r/7zip/" refuri="http://www.djangoproject.com/r/7zip/">http://www.djangoproject.com/r/7zip/</reference>)来解压缩<literal>.tar.gz</literal>文件。 翻译
71#翻译 Once you've unzipped the file, start up a DOS shell (the Command Prompt) with administrator privileges and run the following command from within the directory whose name starts with <literal>Django-</literal> : 解压缩完成后,以管理员权限启动一个DOS Shell(命令提示符),然后在名字以<literal>Django-</literal>开始的目录里执行如下命令: 翻译
74#翻译 In case you're curious: 如果你很好奇: 翻译
75#翻译 Django's files will be installed into your Python installation's <literal>site-packages</literal> directory a directory where Python looks for third-party libraries. Django将被安装到你的Python安装目录<literal> 的site-package</literal> 目录(Python从该目录寻找第三方库)。 翻译
76#翻译 Usually it's in a place like <literal>/usr/lib/python2.4/site-packages</literal> . 通常情况下,这个目录在<literal>/usr/lib/python2.4/site-packages</literal>。 翻译
78#翻译 Installing the Trunk Version 安装Trunk版本 翻译
80#翻译 The latest and greatest Django development version is referred to as <emphasis>trunk</emphasis> , and it's available from Django's Subversion repository. 最新最好的django的开发版本称为trunk,可以从django的subversion处获得。 翻译
81#翻译 You should consider installing this version if you want to work on the bleeding edge, or if you want to contribute code to Django itself. 如果你想尝鲜,或者想为django贡献代码,那么你应当安装这个版本。 翻译
83#翻译 Subversion is a free, open source revision-control system, and the Django team uses it to manage changes to the Django codebase. Subversion 是一种与 CVS 类似的免费开源版本控制系统,Django 开发团队使用它管理 Django 代码库的更新。 翻译
84#翻译 You can use a Subversion client to grab the very latest Django source code and, at any given time, you can update your local version of the Django code, known as your <emphasis>local checkout</emphasis> , to get the latest changes and improvements made by Django developers. 你可以使用 Subversion 客户端获取最新的 Django 源代码,并可任何时候使用 <emphasis>local checkout</emphasis> 更新本地 Django 代码的版本,以获取 Django 开发者所做的最近更新和改进。 翻译
86#翻译 When using trunk, keep in mind there's no guarantee things wont be broken at any given moment. 请记住,即使是使用trunk版本,也是有保障的。 翻译
87#翻译 With that said, though, some members of the Django team run production sites on trunk, so they have an incentive to keep it stable. 因为很多django的开发者在正式网站上就是用的trunk版本,他们会保证trunk版本的稳定性。 翻译
89#翻译 To grab the latest Django trunk, follow these steps: 遵循以下步骤以获取最新的 Django 主流代码: 翻译
91#翻译 Make sure you have a Subversion client installed. 确保安装了 Subversion 客户端。 翻译
92#翻译 You can get the software free from <reference name="http://subversion.tigris.org/" refuri="http://subversion.tigris.org/">http://subversion.tigris.org/</reference>, and you can find excellent documentation at <reference name="http://svnbook.red-bean.com/" refuri="http://svnbook.red-bean.com/">http://svnbook.red-bean.com/</reference>. 可以从 <reference name="http://subversion.tigris.org/" refuri="http://subversion.tigris.org/">http://subversion.tigris.org/</reference> 免费下载该软件,并从 <reference name="http://svnbook.red-bean.com/" refuri="http://svnbook.red-bean.com/">http://svnbook.red-bean.com/</reference> 获取出色的文档。 翻译
94#翻译 (If you're on a Mac with OS X 10.5 or later, you're in luck; Subversion should already be installed. (如果你在使用Mac OS X 10.5或者更新的版本,你很走运,Subversion应该就可以安装Django。 翻译
95#翻译 You can verify this by typing <literal>svn --version</literal> in the Terminal.) 你可以在终端上输入<literal>svn --version</literal>来验证。 翻译
97#翻译 Check out the trunk using the command <literal>svn co http://code.djangoproject.com/svn/django/trunk djtrunk</literal> . 使用 <literal>svn co http://code.djangoproject.com/svn/django/trunk djtrunk</literal> 命令查看主体代码。 翻译
99#翻译 Locate your Python installation's <literal>site-packages</literal> directory. 找到你的python的site-packages目录。 翻译
100#翻译 Usually it's in a place like <literal>/usr/lib/python2.4/site-packages</literal> . If you have no idea, type this command from a command prompt: 一般为/usr/lib/python2.4/site-packages,如果你不确定,可以输入如下命令: 翻译
103#翻译 The resulting output should include your <literal>site-packages</literal> directory. 上面的结果会包含site-packages的目录 翻译
105#翻译 # Within the <literal>site-packages</literal> directory, create a file called 在site-packages目录下,创建一个文件 翻译
107#翻译 <literal>django.pth</literal> and edit it to contain the full path to your <literal>djtrunk</literal> directory to it. django.pth,编辑这个文件,包含djtrunk目录的全路径 翻译
108#翻译 For example, the file could just contain this line: 利润,此文件包含如下行: 翻译
111#翻译 Place <literal>djtrunk/django/bin</literal> on your system PATH. 将 <literal>djtrunk/django/bin</literal> 加入系统变量 PATH 中。该目录中包含一些像 <literal>django-admin.py</literal> 之类的管理工具。 翻译
112#翻译 This directory includes management utilities such as <literal>django-admin.py</literal> . 此目录包含管理工具,例如:django-admin.py 翻译
114#翻译 Tip: 提示: 翻译
116#翻译 If <literal>.pth</literal> files are new to you, you can learn more about them at <reference name="http://www.djangoproject.com/r/python/site-module/" refuri="http://www.djangoproject.com/r/python/site-module/">http://www.djangoproject.com/r/python/site-module/</reference>. 如果之前没有接触过 <literal>.pth</literal> 文件,你可以从 <reference name="http://www.djangoproject.com/r/python/site-module/" refuri="http://www.djangoproject.com/r/python/site-module/">http://www.djangoproject.com/r/python/site-module/</reference> 中获取更多相关知识。 翻译
118#翻译 After downloading from Subversion and following the preceding steps, there's no need to run <literal>python setup.py install</literal> you've just done the work by hand! 从 Subversion 完成下载并执行了前述步骤后,就没有必要再执行 <literal>python setup.py install</literal> 了,你刚才已经手动完成了安装! 翻译
120#翻译 Because the Django trunk changes often with bug fixes and feature additions, you'll probably want to update it every once in a while. 由于 Django 主干代码的更新经常包括 bug 修正和特性添加,如果真的着迷的话,你可能每隔一小段时间就想更新一次。 翻译
121#翻译 To update the code, just run the command <literal>svn update</literal> from within the <literal>djtrunk</literal> directory. 在 <literal>djtrunk</literal> 目录下运行 <literal>svn update</literal> 命令即可进行更新。 翻译
122#翻译 When you run that command, Subversion will contact <reference name="http://code.djangoproject.com" refuri="http://code.djangoproject.com">http://code.djangoproject.com</reference>, determine whether any of Django's code has changed, and update your local version of the code with any changes that have been made since you last updated. 当你使用这个命令时,Subversion 会联络 <reference refuri="http://code.djangoproject.com">http://code.djangoproject.com</reference> ,判断代码是否有更新,然后把上次更新以来的所有变动应用到本地代码。 翻译
123#翻译 It's quite slick. 就这么简单。 翻译
125#翻译 Finally, if you use trunk, you should know how to figure out which version of trunk you're running. 最后,如果你使用trunk,你要知道使用的是哪个trunk版本。 翻译
126#翻译 Knowing your version number is important if you ever need to reach out to the community for help, or if you submit improvements to the framework. 如果你去社区寻求帮助,或是为Django框架提供改进,知道你使用的版本号是非常重要的。 翻译
127#翻译 In these cases, you should tell people the trunk version, also known as a revision number or changeset, that you're using. 因此,当你到社区去求助,或者为 django 提供改进意见的时候,请时刻记住说明你正在使用的 django 的版本号。 翻译
128#翻译 To find out your revision number, type svn info from within the <literal>djtrunk</literal> directory, and look for the number after Revision:. 如何知道你正在使用的 django 的版本号呢?进入<literal> djtrunk</literal> 目录,然后键入 svn info ,在输出信息中查看 Revision: (版本:) 后跟的数字。 翻译
129#翻译 This number is incremented each time Django is changed, whether through a bug fix, feature addition, documentation improvement or anything else. Django在每次更新后,版本号都是递增的,无论是修复Bug、增加特性、改进文档或者是其他。 翻译
130#翻译 Among some members of the Django community, it's a badge of honor to be able to say, Ive been using Django since [insert very low revision number here]. 在一些Django社区中,版本号甚至成为了一种荣誉的象征,我从[写上非常低的版本号]开始就已经使用Djano了。 翻译
132#翻译 Testing the Django installation 测试Django安装 翻译
134#翻译 For some post-installation positive feedback, take a moment to test whether the installation worked. 让我们花点时间去测试 Django 是否安装成功,并工作良好。同时也可以了解到一些明确的安装后的反馈信息。 翻译
135#翻译 In a command shell, change into another directory (e.g., <emphasis>not</emphasis> the directory that contains the <literal>django</literal> directory) and start the Python interactive interpreter by typing <literal>python</literal> . If the installation was successful, you should be able to import the module <literal>django</literal> : 在Shell中,更换到另外一个目录(不是包含Django的目录),然后输入<literal>python</literal>来打开Python的交互解释器。如果安装成功,你应该可以导入<literal>django</literal>模块了: 翻译
138#翻译 Interactive Interpreter Examples 交互解释器示例 翻译
140#翻译 The Python interactive interpreter is a command-line program that lets you write a Python program interactively. Python 交互解释器是命令行窗口的程序,通过它可以交互式地编写 Python 程序。 翻译
141#翻译 To start it, run the command <literal>python</literal> at the command line. 要启动它只需运行 <literal>python</literal> 命令。 翻译
143#翻译 Throughout this book, we feature example Python interactive interpreter sessions. 我们在交互解释器中演示Python示例将贯穿整本书。 翻译
144#翻译 You can recognize these examples by the triple greater-than signs (<literal>>>></literal> ), which designate the interpreter's prompt. 你可以用三个大于号 (<literal>>>></literal> )来分辨出示例,三个大于号就表示交互提示符。 翻译
145#翻译 If youre copying examples from this book, don't copy those greater-than signs. 如果你要从本书中拷贝示例,请不要拷贝提示符。 翻译
147#翻译 Multiline statements in the interactive interpreter are padded with three dots (<literal>...</literal> 在交互式解释器中,多行声明用三个点 (<literal>...</literal>)来填补。 翻译
148#翻译 ). For example: 例如: 翻译
151#翻译 Those three dots at the start of the additional lines are inserted by the Python shell they're not part of our input. 这三个在新行开始插入的点,是Python Shell自行加入的,不属于我们的输入。 翻译
152#翻译 We include them here to be faithful to the actual output of the interpreter. 但是包含它们是为了追求解释器的正确输出。 翻译
153#翻译 If you copy our examples to follow along, don't copy those dots. 如果你拷贝我们的示例去运行,千万别拷贝这些点。 翻译
155#翻译 Setting Up a Database 安装数据库 翻译
157#翻译 At this point, you could very well begin writing a Web application with Django, because Django's only hard-and-fast prerequisite is a working Python installation. 这会儿,你可以使用django写web应用了,因为django只要求python正确安装后就可以跑起来了。 翻译
158#翻译 However, odds are you'll be developing a <emphasis>database-driven</emphasis> Web site, in which case you'll need to configure a database server. 不过,当你想开发一个<emphasis>数据库驱动</emphasis>的web站点时,你应当需要配置一个数据库服务器。 翻译
160#翻译 If you just want to start playing with Django, skip ahead to the Starting a Project section but keep in mind that all the examples in this book assume you have a working database set up. 如果你只想玩一下,可以不配置数据库,直接跳到 开始一个project 部分去,不过你要注意本书的例子都是假设你配置好了一个正常工作的数据库。 翻译
162#翻译 Django supports four database engines: Django支持四种数据库: 翻译
164#翻译 PostgreSQL (<reference name="http://www.postgresql.org/" refuri="http://www.postgresql.org/">http://www.postgresql.org/</reference>) PostgreSQL (<reference name="http://www.postgresql.org/" refuri="http://www.postgresql.org/">http://www.postgresql.org/</reference>) 翻译
166#翻译 SQLite 3 (<reference name="http://www.sqlite.org/" refuri="http://www.sqlite.org/">http://www.sqlite.org/</reference>) SQLite 3 (<reference name="http://www.sqlite.org/" refuri="http://www.sqlite.org/">http://www.sqlite.org/</reference>) 翻译
168#翻译 MySQL (<reference name="http://www.mysql.com/" refuri="http://www.mysql.com/">http://www.mysql.com/</reference>) MySQL (<reference name="http://www.mysql.com/" refuri="http://www.mysql.com/">http://www.mysql.com/</reference>) 翻译
170#翻译 Oracle (<reference name="http://www.oracle.com/" refuri="http://www.oracle.com/">http://www.oracle.com/</reference>) Oracle (<reference name="http://www.oracle.com/" refuri="http://www.oracle.com/">http://www.oracle.com/</reference>) 翻译
172#翻译 For the most part, all the engines here work equally well with the core Django framework. 大部分情况下,这四种数据库都会和Django框架很好的工作。 翻译
173#翻译 (A notable exception is Django's optional GIS support, which is much more powerful with PostgreSQL than with other databases.) If you're not tied to any legacy system and have the freedom to choose a database backend, we recommend PostgreSQL, which achieves a fine balance between cost, features, speed and stability. (一个值得注意的例外是Django的可选GIS支持,它为PostgreSQL提供了强大的功能。)如果你不准备使用一些老旧系统,而且可以自由的选择数据库后端,我们推荐你使用PostgreSQL,它在成本、特性、速度和稳定性方面都做的比较平衡。 翻译
175#翻译 Setting up the database is a two-step process: 设置数据库只需要两步: 翻译
177#翻译 First, you'll need to install and configure the database server itself. 首先,你需要安装和配置数据库服务器本身。 翻译
178#翻译 This process is beyond the scope of this book, but each of the four database backends has rich documentation on its Web site. 这个过程超出了本书的内容,不过这四种数据库后端在它的网站上都有丰富的文档说明。 翻译
179#翻译 (If you're on a shared hosting provider, odds are that they've set this up for you already.) 如果你使用的是共享主机,可能它们已经为你设置好了。 翻译
181#翻译 Second, you'll need to install the Python library for your particular database backend. 其次,你需要为你的服务器后端安装必要的Python库。 翻译
182#翻译 This is a third-party bit of code that allows Python to interface with the database. 这是一些允许Python连接数据库的第三方代码。 翻译
183#翻译 We outline the specific, per-database requirements in the following sections. 我们会在之后的章节简要介绍,对于某一种数据库来说,它单独需要安装的东西。 翻译
185#翻译 If you're just playing around with Django and don't want to install a database server, consider using SQLite. 如果你只是玩一下,不想安装数据库服务,那么可以考虑使用SQLite。 翻译
186#翻译 SQLite is unique in the list of supported databases in that it doesn't require either of the above steps, if you're using Python 2.5 or higher. 如果你用python2.5或更高版本的话,SQLite是唯一一个被支持的且不需要以上安装步骤的数据库。 翻译
187#翻译 It merely reads and writes its data to a single file on your filesystem, and Python versions 2.5 and higher include built-in support for it. 它仅对你的文件系统中的单一文件读写数据,并且Python2.5和以后版本内建了对它的支持。 翻译
189#翻译 On Windows, obtaining database driver binaries can be frustrating. 在Windows上,取得数据库驱动程序可能会令人沮丧。 翻译
190#翻译 If you're eager to jump in, we recommend using Python 2.5 and its built-in support for SQLite. 如果你急着用它,我们建议你使用python2.5。 翻译
192#翻译 Using Django with PostgreSQL 在 Django 中使用 PostgreSQL 翻译
194#翻译 If you're using PostgreSQL, you'll need to install either the <literal>psycopg</literal> or <literal>psycopg2</literal> package from <reference name="http://www.djangoproject.com/r/python-pgsql/" refuri="http://www.djangoproject.com/r/python-pgsql/">http://www.djangoproject.com/r/python-pgsql/</reference>. 使用 PostgreSQL 的话,你需要从 <reference name="http://www.djangoproject.com/r/python-pgsql/" refuri="http://www.djangoproject.com/r/python-pgsql/">http://www.djangoproject.com/r/python-pgsql/</reference> 下载 <literal>psycopg</literal> 这个开发包。 翻译
195#翻译 We recommend <literal>psycopg2</literal> , as it's newer, more actively developed and can be easier to install. 我们建议使用<literal>psycopg2</literal>,因为它是新的,开发比较积极,且更容易安装。 翻译
196#翻译 Either way, take note of whether you're using version 1 or 2; youll need this information later. 留意你所用的是 版本 1 还是 2,稍后你会需要这项信息。 翻译
198#翻译 If you're using PostgreSQL on Windows, you can find precompiled binaries of <literal>psycopg</literal> at <reference name="http://www.djangoproject.com/r/python-pgsql/windows/" refuri="http://www.djangoproject.com/r/python-pgsql/windows/">http://www.djangoproject.com/r/python-pgsql/windows/</reference>. 如果在 Windows 平台上使用 PostgreSQL,可以从 <reference name="http://www.djangoproject.com/r/python-pgsql/windows/" refuri="http://www.djangoproject.com/r/python-pgsql/windows/">http://www.djangoproject.com/r/python-pgsql/windows/</reference> 获取预编译的 <literal>psycopg</literal> 开发包的二进制文件。 翻译
200#翻译 If you're on Linux, check whether your distribution's package-management system offers a package called python-psycopg2, psycopg2-python, python-postgresql or something similar. 如果你在用Linux,检查你的发行版的软件包管理系统是否提供了一套叫做python-psycopg2,psycopg2-python,python-postgresql这类名字的包。 翻译
202#翻译 Using Django with SQLite 3 在 Django 中使用 SQLite 3 翻译
204#翻译 If you're using Python version 2.5 or higher, you're in luck: 如果你正在使用Python 2.5版本或者更高,那么你很幸运: 翻译
205#翻译 no database-specific installation is required, because Python ships with SQLite support. 不要求安装特定的数据库,因为Python支持和SQLite进行通信。 翻译
206#翻译 Skip ahead to the next section. 向前跳到下一节。 翻译
208#翻译 If you're working with Python 2.4 or older, you'll need SQLite 3 <emphasis>not</emphasis> version 2 from <reference name="http://www.djangoproject.com/r/sqlite/" refuri="http://www.djangoproject.com/r/sqlite/">http://www.djangoproject.com/r/sqlite/</reference> and the <literal>pysqlite</literal> package from <reference name="http://www.djangoproject.com/r/python-sqlite/" refuri="http://www.djangoproject.com/r/python-sqlite/">http://www.djangoproject.com/r/python-sqlite/</reference>. 如果你用的是Python2.4或更早的版本,你需要 SQLite 3<emphasis>而不是</emphasis>版本2,这个可从<reference name="http://www.djangoproject.com/r/sqlite/" refuri="http://www.djangoproject.com/r/sqlite/">http://www.djangoproject.com/r/sqlite/</reference><literal>pysqlite</literal><reference name="http://www.djangoproject.com/r/python-sqlite/" refuri="http://www.djangoproject.com/r/python-sqlite/">http://www.djangoproject.com/r/python-sqlite/</reference> 翻译
209#翻译 Make sure you have <literal>pysqlite</literal> version 2.0.3 or higher. 确认一下你的<literal>pysqlite</literal>版本是2.0.3或者更高。 翻译
211#翻译 On Windows, you can skip installing the former (the separate SQLite binaries), because they're statically linked into the <literal>pysqlite</literal> binaries. 在 Windows 平台上,可以跳过单独的 SQLite 二进制包安装工作,因为它们已被静态链接到 <literal>pysqlite</literal> 二进制开发包中。 翻译
213#翻译 If you're on Linux, check whether your distribution's package-management system offers a package called python-sqlite3, sqlite-python, pysqlite or something similar. 如果你在用Linux,检查你的发行版的软件包管理系统是否提供了一套叫做python-sqlite3,sqlite-python,pysqlite这类名字的包。 翻译
215#翻译 Using Django with MySQL 在 Django 中使用 MySQL 翻译
217#翻译 Django requires MySQL 4.0 or above. django要求MySQL4.0或更高的版本。 翻译
218#翻译 The 3.x versions don't support nested subqueries and some other fairly standard SQL statements. 3.X 版本不支持嵌套子查询和一些其它相当标准的SQL语句。 翻译
220#翻译 You'll also need to install the <literal>MySQLdb</literal> package from <reference name="http://www.djangoproject.com/r/python-mysql/" refuri="http://www.djangoproject.com/r/python-mysql/">http://www.djangoproject.com/r/python-mysql/</reference>. 你还需要从 <reference name="http://www.djangoproject.com/r/python-mysql/" refuri="http://www.djangoproject.com/r/python-mysql/">http://www.djangoproject.com/r/python-mysql/</reference> 下载安装 <literal>MySQLdb</literal> 。 翻译
222#翻译 If you're on Linux, check whether your distribution's package-management system offers a package called python-mysql, python-mysqldb, mysql-python or something similar. 如果你正在使用Linux,检查下你系统的包管理器是否提供了叫做python-mysql,python-mysqldb,myspl-python或者相似的包。 翻译
224#翻译 Using Django with Oracle 在Django中使用Oracle数据库 翻译
226#翻译 Django works with Oracle Database Server versions 9i and higher. django需要Oracle9i或更高版本。 翻译
228#翻译 If you're using Oracle, youll need to install the <literal>cx_Oracle</literal> library, available at <reference name="http://cx-oracle.sourceforge.net/" refuri="http://cx-oracle.sourceforge.net/">http://cx-oracle.sourceforge.net/</reference>. 如果你用Oracle,你需要安装<literal>cx_Oracle</literal>库,可以从<reference name="http://cx-oracle.sourceforge.net/" refuri="http://cx-oracle.sourceforge.net/">http://cx-oracle.sourceforge.net/</reference>获得。 翻译
229#翻译 Use version 4.3.1 or higher, but avoid version 5.0 due to a bug in that version of the driver. 要用4.3.1或更高版本,但要避开5.0,这是因为这个版本的驱动有bug。 翻译
231#翻译 Using Django Without a Database 使用无数据库支持的 Django 翻译
233#翻译 As mentioned earlier, Django doesn't actually require a database. 正如之前提及过的,Django 并不是非得要数据库才可以运行。 翻译
234#翻译 If you just want to use it to serve dynamic pages that don't hit a database, thats perfectly fine. 如果只用它提供一些不涉及数据库的动态页面服务,也同样可以完美运行。 翻译
236#翻译 With that said, bear in mind that some of the extra tools bundled with Django <emphasis>do</emphasis> require a database, so if you choose not to use a database, you'll miss out on those features. 尽管如此,还是要记住: Django 所捆绑的一些附加工具 一定 需要数据库,因此如果选择不使用数据库,你将不能使用那些功能。 翻译
237#翻译 (We highlight these features throughout this book.) (我们将在本书中自始至终强调这些功能) 翻译
239#翻译 Starting a Project 开始一个项目 翻译
241#翻译 Once you've installed Python, Django and (optionally) your database server/library, you can take the first step in developing a Django application by creating a <emphasis>project</emphasis> . 一但你安装好了python,django和(可选的)数据库及相关库,你就可以通过创建一个<emphasis>project</emphasis>,迈出开发django应用的第一步。 翻译
243#翻译 A project is a collection of settings for an instance of Django, including database configuration, Django-specific options and application-specific settings. 项目 是 Django 实例的一系列设置的集合,它包括数据库配置、Django 特定选项以及应用程序的特定设置。 翻译
245#翻译 If this is your first time using Django, you'll have to take care of some initial setup. 如果第一次使用 Django,必须进行一些初始化设置工作。 翻译
246#翻译 Create a new directory to start working in, perhaps something like <literal>/home/username/djcode/</literal> . 新建一个工作目录,例如 <literal>/home/username/djcode/</literal> ,然后进入该目录。 翻译
248#翻译 Where Should This Directory Live? 这个目录应该放哪儿? 翻译
250#翻译 If your background is in PHP, you're probably used to putting code under the Web server's document root (in a place such as <literal>/var/www</literal> ). With Django, you don't do that. 有过 PHP 编程背景的话,你可能习惯于将代码都放在 Web 服务器的文档根目录 (例如 <literal>/var/www</literal> 这样的地方)。 翻译
251#翻译 It's not a good idea to put any of this Python code within your Web server's document root, because in doing so you risk the possibility that people will be able to view your raw source code over the Web. 而在 Django 中,把任何Python代码和web server的文档根(root)放在一起并不是一个好主意。因为这样做有使人能通过网路看到你原代码的风险. 翻译
252#翻译 That's not good. 那就太糟了。 翻译
254#翻译 Put your code in some directory <strong>outside</strong> of the document root. 把代码放置在文档根目录 <strong>之外</strong> 的某些目录中。 翻译
256#翻译 Change into the directory you created, and run the command <literal>django-admin.py startproject mysite</literal> . This will create a <literal>mysite</literal> directory in your current directory. 转到你创建的目录,运行命令<literal>django-admin.py startproject mysite</literal>。这样会在你的当前目录下创建一个目录。<literal>mysite</literal> 翻译
258#翻译 Note 注意 翻译
260#翻译 <literal>django-admin.py</literal> should be on your system path if you installed Django via its <literal>setup.py</literal> utility. 如果用的是 <literal>setup.py</literal> 工具安装的 Django , <literal>django-admin.py</literal> 应该已被加入了系统路径中。 翻译
262#翻译 If you're using trunk, youll find <literal>django-admin.py</literal> in <literal>djtrunk/django/bin</literal> . Because you'll be using <literal>django-admin.py</literal> often, consider adding it to your system path. 如果你使用一个trunk版本,你会在 <literal>djtrunk/django/bin</literal> 下发现 <literal>django-admin.py</literal> 。你将来会常用到<literal>django-admin.py</literal>,考虑把它加到你的系统路径中去比较好。 翻译
263#翻译 On Unix, you can do so by symlinking from <literal>/usr/local/bin</literal> , using a command such as <literal>sudo ln -s /path/to/django/bin/django-admin.py /usr/local/bin/django-admin.py</literal> . On Windows, you'll need to update your <literal>PATH</literal> environment variable. 在Unix中, 你也可以用来自<literal>/usr/local/bin</literal> 的符号连接, 用一个命令, 诸如<literal>sudo ln -s /path/to/django/bin/django-admin.py /usr/local/bin/django-admin.py</literal> . 在Windows中, 你需要修改你的 <literal>PATH</literal> 环境变量. 翻译
265#翻译 If you installed Django from a packaged version for your Linux distribution, <literal>django-admin.py</literal> might be called <literal>django-admin</literal> instead. 如果你的django是从linux发行版中安装的,那么,常会被<literal>django-admin.py</literal>替代。<literal>django-admin</literal> 翻译
267#翻译 If you see a permission denied message when running <literal>django-admin.py startproject</literal> , you'll need to change the file's permissions. 如果在运行时,你看到权限拒绝的提示,你应当修改这个文件的权限。<literal>django-admin.py startproject</literal> 翻译
268#翻译 To do this, navigate to the directory where <literal>django-admin.py</literal> is installed (e.g., <literal>cd /usr/local/bin</literal> ) and run the command <literal>chmod +x django-admin.py</literal> . 为此, 键入 <literal>cd /usr/local/bin</literal>转到<literal>django-admin.py</literal>所在的目录,运行命令<literal>chmod +x django-admin.py</literal> 翻译
270#翻译 The <literal>startproject</literal> command creates a directory containing four files: <literal>startproject</literal> 命令创建一个目录,包含4个文件: 翻译
273#翻译 These files are as follows: 文件如下: 翻译
275#翻译 <literal>__init__.py</literal> : A file required for Python to treat the <literal>mysite</literal> directory as a package (i.e., a group of Python modules). <literal>__init__.py</literal> :让 Python 把该目录当成一个开发包 (即一组模块)所需的文件。 翻译
276#翻译 It's an empty file, and generally you won't add anything to it. 这是一个空文件,一般你不需要修改它。 翻译
278#翻译 <literal>manage.py</literal> : A command-line utility that lets you interact with this Django project in various ways. <literal>manage.py</literal> :一种命令行工具,允许你以多种方式与该 Django 项目进行交互。 翻译
279#翻译 Type <literal>python manage.py help</literal> to get a feel for what it can do. 键入<literal>python manage.py help</literal>,看一下它能做什么。 翻译
280#翻译 You should never have to edit this file; it's created in this directory purely for convenience. 你应当不需要编辑这个文件;在这个目录下生成它纯是为了方便。 翻译
282#翻译 <literal>settings.py</literal> : Settings/configuration for this Django project. <literal>settings.py</literal> :该 Django 项目的设置或配置。 翻译
283#翻译 Take a look at it to get an idea of the types of settings available, along with their default values. 查看并理解这个文件中可用的设置类型及其默认值。 翻译
285#翻译 <literal>urls.py</literal> : The URLs for this Django project. <literal>urls.py</literal>:Django项目的URL设置。 翻译
286#翻译 Think of this as the table of contents of your Django-powered site. 可视其为你的django网站的目录。 翻译
287#翻译 At the moment, it's empty. 目前,它是空的。 翻译
289#翻译 Despite their small size, these files already constitute a working Django application. 尽管这些的文件很小,但这些文件已经构成了一个可运行的Django应用。 翻译
291#翻译 Running the Development Server 运行开发服务器 翻译
293#翻译 For some more post-installation positive feedback, let's run the Django development server to see our barebones application in action. 为了安装后更多的体验,让我们运行一下django开发服务器看看我们的准系统。 翻译
295#翻译 The Django development server (also called the runserver after the command that launches it) is a built-in, lightweight Web server you can use while developing your site. django开发服务是可用在开发期间的,一个内建的,轻量的web服务。 翻译
296#翻译 It's included with Django so you can develop your site rapidly, without having to deal with configuring your production server (e.g., Apache) until you're ready for production. 我们提供这个服务器是为了让你快速开发站点,也就是说在准备发布产品之前,无需进行产品级 Web 服务器(比如 Apache)的配置工作。 翻译
297#翻译 The development server watches your code and automatically reloads it, making it easy for you to change your code without needing to restart anything. 开发服务器监测你的代码并自动加载它,这样你会很容易修改代码而不用重启动服务。 翻译
299#翻译 To start the server, change into your project directory (<literal>cd mysite</literal> ), if you haven't already, and run this command: 如果你还没启动服务器的话,请切换到你的项目目录里 (<literal>cd mysite</literal> ),运行下面的命令: 翻译
302#翻译 You'll see something like this: 你会看到些像这样的 翻译
305#翻译 This launches the server locally, on port 8000, accessible only to connections from your own computer. 这将会在端口8000启动一个本地服务器, 并且只能从你的这台电脑连接和访问。 翻译
306#翻译 Now that it's running, visit <reference name="http://127.0.0.1:8000/" refuri="http://127.0.0.1:8000/">http://127.0.0.1:8000/</reference> with your Web browser. 既然服务器已经运行起来了,现在用网页浏览器访问 <reference name="http://127.0.0.1:8000/" refuri="http://127.0.0.1:8000/">http://127.0.0.1:8000/</reference> 。 翻译
307#翻译 You'll see a Welcome to Django page shaded in a pleasant pastel blue. 你应该可以看到一个令人赏心悦目的淡蓝色Django欢迎页面。 翻译
308#翻译 It worked! 它开始工作了。 翻译
310#翻译 One final, important note about the development server is worth mentioning before proceeding. 在进一步学习之前, 一个重要的,关于开发网络服务器的提示很值得一说。 翻译
311#翻译 Although this server is convenient for development, resist the temptation to use it in anything resembling a production environment. 虽然 django 自带的这个 web 服务器对于开发很方便,但是,千万不要在正式的应用布署环境中使用它。 翻译
312#翻译 The development server can handle only a single request at a time reliably, and it has not gone through a security audit of any sort. 在同一时间,该服务器只能可靠地处理一次单个请求,并且没有进行任何类型的安全审计。 翻译
313#翻译 When the time comes to launch your site, see Chapter 12 for information on how to deploy Django. 发布站点前,请参阅第 20 章了解如何部署 Django 。 翻译
315#翻译 Changing the Development Server's Host or Port 更改这个 Development Server 的主机地址或端口 翻译
317#翻译 By default, the <literal>runserver</literal> command starts the development server on port 8000, listening only for local connections. 默认情况下, <literal>runserver</literal> 命令在 8000 端口启动开发服务器,且仅监听本地连接。 翻译
318#翻译 If you want to change the server's port, pass it as a command-line argument: 要想要更改服务器端口的话,可将端口作为命令行参数传入: 翻译
321#翻译 By specifying an IP address, you can tell the server to allow non-local connections. 通过指定一个 IP 地址,你可以告诉服务器---允许非本地连接访问。 翻译
322#翻译 This is especially helpful if you'd like to share a development site with other members of your team. 如果你想和其他开发人员共享同一开发站点的话,该功能特别有用。 翻译
323#翻译 The IP address <literal>0.0.0.0</literal> tells the server to listen on any network interface: <literal> 0.0.0.0</literal> 这个 IP 地址,告诉服务器去侦听任意的网络接口。 翻译
326#翻译 When you've done this, other computers on your local network will be able to view your Django site by visiting your IP address in their Web browsers, e.g., <reference name="http://192.168.1.103:8000/" refuri="http://192.168.1.103:8000/">http://192.168.1.103:8000/</reference> . (Note that you'll have to consult your network settings to determine your IP address on the local network. 完成这些设置后,你本地网络中的其它计算机就可以在浏览器中访问你的 IP 地址了。比如: <reference name="http://192.168.1.103:8000/" refuri="http://192.168.1.103:8000/">http://192.168.1.103:8000/</reference> . (注意,你将需要校阅一下你的网络配置来决定你在本地网络中的IP 地址) 翻译
327#翻译 Unix users, try running ifconfig in a command prompt to get this information. Unix用户可以在命令提示符中输入ifconfig来获取以上信息。 翻译
328#翻译 Windows users, try ipconfig.) 使用Windows的用户,请尝试使用 ipconfig 命令。 翻译
330#翻译 What's Next? 接下来做什么? 翻译
332#翻译 Now that you have everything installed and the development server running, you're ready to <reference name="learn the basics" refuri="../chapter03/">learn the basics</reference> of serving Web pages with Django. 好了,你已经安装好所需的一切, 并且开发服务器也运行起来了,你已经准备好继续 <reference name="learn the basics" refuri="../chapter03/">学习基础知识---用Django伺候网頁</reference> 这一章的内容了。 翻译