﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-杂家杂谈-随笔分类-Django</title><link>http://www.blogjava.net/glorywine/category/32061.html</link><description /><language>zh-cn</language><lastBuildDate>Tue, 16 Sep 2008 19:15:16 GMT</lastBuildDate><pubDate>Tue, 16 Sep 2008 19:15:16 GMT</pubDate><ttl>60</ttl><item><title>Django on Jython</title><link>http://www.blogjava.net/glorywine/archive/2008/09/17/229275.html</link><dc:creator>glorywine</dc:creator><author>glorywine</author><pubDate>Tue, 16 Sep 2008 16:41:00 GMT</pubDate><guid>http://www.blogjava.net/glorywine/archive/2008/09/17/229275.html</guid><wfw:comment>http://www.blogjava.net/glorywine/comments/229275.html</wfw:comment><comments>http://www.blogjava.net/glorywine/archive/2008/09/17/229275.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/glorywine/comments/commentRss/229275.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/glorywine/services/trackbacks/229275.html</trackback:ping><description><![CDATA[
		<font size="2" face="Courier New">   使用Django已经一段时间了，非常喜欢这样的状态，很少的配置文件和代码，就可以样一个原型跑起来。1.0已经发布一段时间了，有了很多的改变，改进，很吸引眼球。但是还有一个特性非常吸引我，Django可以运行在Jython上了，这就意味着，可以在Tomcat,Glassfish等服务器上跑Django了，EXCITING?<br /><br />   OK, Let's give a shot!</font>
		<font size="2" face="Courier New">
				<br />   1. of course, 先要现在Django</font>，<font size="2" face="Courier New">不过我还是推荐使用svn中的代码</font>。<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><font face="Courier New"><span style="color: rgb(0, 0, 0);">svn co http:</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">code.djangoproject.com/svn/django/trunk/ django-dev</span></font><span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);"></span></div>  <font size="2" face="Courier New"> 2. 接着就要下载Jython了，当前的stable版本是2.2.1，而我们需要的是2.5，该版本还是alpha阶段，所以，还是从svn中获取。<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">svn co https:</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">jython.svn.sourceforge.net/svnroot/jython/trunk/jython/ jython-dev</span></div>   完成了Jython的检出，开始编译工作。需要指出的是，我们在这里使用ant来构建Jython，当然，也可以选择maven，看个人习惯了，ant和maven的具体安装方法大家可以去google，这里不再累述。<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">cd jython</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">dev<br />ant</span></div>   稍等片刻，就可以完成编译工作了，生成的文件在jython-dev下的dist文件夹下。然后，我将dist下的文件全部拷贝到D:/jython下，我在这里使用的是windows，大家可以根据自己的平台进行设置。<br />   为了能在console里使用Jython，我们还需要将jython目录下的bin文件夹添加到path。这里大家也可以去google，不再多说。现在打开一个console，输入jython，是不是能看到非常熟悉的，python控制台呢？<br />   3. 好的，现在就需要安装Django了。<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">cd django</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">dev<br />jython setup.py build<br />jython setup.py install</span></div>   安装完成后，就可以在jython/Lib/site-packages下看到Django了。为了查看是否安装成功，使用下面的方法。打开控制台：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">D:\</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">jython<br />Jython </span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">.5a3</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> (trunk, </span><span style="color: rgb(0, 0, 0);">????</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">16</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">2008</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">18</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">50</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">22</span><span style="color: rgb(0, 0, 0);">)<br />[Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] on java1.</span><span style="color: rgb(0, 0, 0);">6</span><span style="color: rgb(0, 0, 0);">.0_10</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">beta<br />Type </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">help</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">copyright</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">credits</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> or </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">license</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> more information.<br /></span><span style="color: rgb(0, 0, 0);">&gt;&gt;&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> django<br /></span><span style="color: rgb(0, 0, 0);">&gt;&gt;&gt;</span><span style="color: rgb(0, 0, 0);"> django.get_version()<br />u</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">1.0-post-release-SVN-SVN-unknown</span><span style="color: rgb(0, 0, 0);">'</span></div>   如果看到了最后的输出就表示安装成功了。<br />   4. 当前Django on Jython只支持postgresql，所以，我们这里还需要下载一个Lib，Django-Jython.<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">svn co http:</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">django-jython.googlecode.com/svn/trunk/ <font color="#000000">django-jython<br />cd django-jython<br />jython setup.py build<br />jython setup.py install<br /></font></span></div>   这样就完成了django-jython的安装。<br />   5. 最后就是安装postgresql数据库了，大家可以根据官方的文档进行安装。<br /><br />   万事俱备，让我们开始真正的Django on Jython之旅吧。<br />   这里还需要说明一点，在完成Django的安装之后，在jython/bin下会有一个django-admin.py，这个是Django命令的工具，为了同CPython下的Django进行区别，我在这里将其重命名为django-admin-jy.py。<br />   好，切换到工作目录。<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">django</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">admin</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">jy.py startproject djangonjython</span></div>   是不是有djangonjython这个目录出现呢？对了，这就是我们创建的工程。<br />   如果你是一个急性子，那么就让我们尝试一下，看看是不是能够运行呢？<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">cd djangonjython<br />jython manage.py runserver</span></div>   熟悉的页面是否出现呢？<br /></font><div align="center"><font size="2" face="Courier New"><img src="http://www.blogjava.net/images/blogjava_net/glorywine/runserver.PNG" alt="runserver.PNG" width="300" border="0" height="179" /></font><br /><div align="left">   <font size="2" face="Courier New">在观察一下djangonjython目录里的文件，哈，没有了.pyc，改成了.class，确实是jython在工作了。<br />   如果只是运行这么一个东西，肯定就没有什么价值了。OK，let's build an application。我们在这里创建一个简单的blog（老生常谈了:)）。<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">jython manage.py startapp blog</span></div>   这样就完成了app的创建，当然在djangonjython下应该多了一个blog文件夹，里面还包含了一些文件。<br />   首先修改models.py，内容如下：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 128);"> 1</span> <span style="color: rgb(0, 0, 255);">from</span><span style="color: rgb(0, 0, 0);"> django.db </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> models<br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">from</span><span style="color: rgb(0, 0, 0);"> django.contrib.auth.models </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> User<br /></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> Entry(models.Model):<br /></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 0, 0);">    STATUS_CHOICES </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (<br /></span><span style="color: rgb(0, 128, 128);"> 6</span> <span style="color: rgb(0, 0, 0);">        (0, </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">live</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">),<br /></span><span style="color: rgb(0, 128, 128);"> 7</span> <span style="color: rgb(0, 0, 0);">        (</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">draft</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">),<br /></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 0, 0);">        (</span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">cancel</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">),<br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 0, 0);">    )<br /></span><span style="color: rgb(0, 128, 128);">10</span> <span style="color: rgb(0, 0, 0);">    author </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> models.ForeignKey(User)<br /></span><span style="color: rgb(0, 128, 128);">11</span> <span style="color: rgb(0, 0, 0);">    title </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> models.CharField(max_length</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">255</span><span style="color: rgb(0, 0, 0);">)<br /></span><span style="color: rgb(0, 128, 128);">12</span> <span style="color: rgb(0, 0, 0);">    slug </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> models.SlugField()<br /></span><span style="color: rgb(0, 128, 128);">13</span> <span style="color: rgb(0, 0, 0);">    content </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> models.TextField()<br /></span><span style="color: rgb(0, 128, 128);">14</span> <span style="color: rgb(0, 0, 0);">    create_at </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> models.DateTimeField(auto_now_add</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">True)<br /></span><span style="color: rgb(0, 128, 128);">15</span> <span style="color: rgb(0, 0, 0);">    status </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> models.IntegerField(default</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">0, choices</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">STATUS_CHOICES)<br /></span><span style="color: rgb(0, 128, 128);">16</span> <span style="color: rgb(0, 0, 0);">    <br /></span><span style="color: rgb(0, 128, 128);">17</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">def</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 128);">__unicode__</span><span style="color: rgb(0, 0, 0);">(self):<br /></span><span style="color: rgb(0, 128, 128);">18</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> self.title<br /></span><span style="color: rgb(0, 128, 128);">19</span> <span style="color: rgb(0, 0, 0);">        <br /></span><span style="color: rgb(0, 128, 128);">20</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">def</span><span style="color: rgb(0, 0, 0);"> get_absolute_url(self):<br /></span><span style="color: rgb(0, 128, 128);">21</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">/blog/%s</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">%</span><span style="color: rgb(0, 0, 0);"> (self.slug)<br /></span><span style="color: rgb(0, 128, 128);">22</span> <span style="color: rgb(0, 0, 0);">        <br /></span><span style="color: rgb(0, 128, 128);">23</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> Meta:<br /></span><span style="color: rgb(0, 128, 128);">24</span> <span style="color: rgb(0, 0, 0);">        ordering </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> [</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">-create_at</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">]</span></div>   这只是一个非常简单的原型，说明问题就行了。好，既然使用了Django 1.0那么就要有一些改变，现在的Django使用了newform-admin，那么就在blog目录下创建admin.py文件，内容如下：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 128);"> 1</span> <span style="color: rgb(0, 0, 255);">from</span><span style="color: rgb(0, 0, 0);"> django.contrib </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> admin<br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">from</span><span style="color: rgb(0, 0, 0);"> djangonjython.blog.models </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> Entry<br /></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> EntryAdmin(admin.ModelAdmin):<br /></span><span style="color: rgb(0, 128, 128);"> 6</span> <span style="color: rgb(0, 0, 0);">    list_display </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">title</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">author</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">create_at</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">status</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,)<br /></span><span style="color: rgb(0, 128, 128);"> 7</span> <span style="color: rgb(0, 0, 0);">    ordering </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> [</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">-create_at</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">]<br /></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 0, 0);">    list_filter </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">author</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">status</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,)<br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 0, 0);">    prepopulated_fields </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> {</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">slug</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">: (</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">title</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,),}<br /></span><span style="color: rgb(0, 128, 128);">10</span> <span style="color: rgb(0, 0, 0);">    <br /></span><span style="color: rgb(0, 128, 128);">11</span> <span style="color: rgb(0, 0, 0);">admin.site.register(Entry, EntryAdmin)</span></div>   这样就将Entry注册到了admin site里，就可以在admin page里进行管理了。<br />   再进一步之前，先启动先前安装的postgresql，创建database blog。完成之后，就要对项目进行一些配置了。<br />   首先是djangonjython目录下的urls.py<br />   取消这几行的注释：<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">from</span><span style="color: rgb(0, 0, 0);"> django.contrib </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> admin<br />admin.autodiscover()<br /><br />(r</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">^admin/(.*)</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">, admin.site.root),</span></div>   为的是能够访问到admin page.<br />   接着是settings.py，<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">DATABASE_ENGINE </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">doj.backends.zxjdbc.postgresql</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">           </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);"> 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">DATABASE_NAME </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">blog</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">             </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);"> Or path to database file if using sqlite3.</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">DATABASE_USER </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">'yourname</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">             </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);"> Not used with sqlite3.</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">DATABASE_PASSWORD </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">yourpassword</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">         </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);"> Not used with sqlite3.</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">DATABASE_HOST </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">''</span><span style="color: rgb(0, 0, 0);">             </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);"> Set to empty string for localhost. Not used with sqlite3.</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">DATABASE_PORT </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">''</span><span style="color: rgb(0, 0, 0);">             </span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);"> Set to empty string for default. Not used with sqlite3.<br /><br /><font color="#000000">INSTALLED_APPS = (<br />    'django.contrib.auth',<br />    'django.contrib.contenttypes',<br />    'django.contrib.sessions',<br />    'django.contrib.sites',<br />    'django.contrib.admin',<br />    'djangonjython.blog',<br />    'doj',<br />)</font><br /></span></div><br />   对上面的代买进行一些说明：<br />   doj.backends.zxjdbc.postgresql是之前安装的django-jython提供的数据支持，当然，要使用这个，必须将doj这个库添加到PYTHONPATH中，所以在下面的INSTALLED_APPS里，加入了doj，而djangonjyton.blog就是之前创建的app。<br />   好，完成了这些，就可以开始数据库的创建了。熟悉的命令：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">jython manage.py syncdb</span></div>   按照上面的提示，一步一步的进行填写。完成之后，启动服务，是不是又是一个熟悉的画面？<br /></font><font size="2" face="Courier New">   填写之前要求的管理员用户名和密码，就进入到了admin page，我习惯称后台管理页面。</font><font size="2" face="Courier New"><br />   好了，在这里就可以添加一些entry了。完成了后台的管理，让我们添加一些前台的显示吧。</font><br /><font size="2" face="Courier New">   在这里，我打算使用django自带的generic views，使用起来非常的简单。为了同项目的urls.py区别开，在blog下创建一个新的urls.py，内容如下：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 128);"> 1</span> <span style="color: rgb(0, 0, 255);">from</span><span style="color: rgb(0, 0, 0);"> django.conf.urls.defaults </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">from</span><span style="color: rgb(0, 0, 0);"> djangonjython.blog.models </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> Entry<br /></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 0, 0);">entry_dict </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> {<br /></span><span style="color: rgb(0, 128, 128);"> 6</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">queryset</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">: Entry.objects.all(),<br /></span><span style="color: rgb(0, 128, 128);"> 7</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">template_object_name</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">: </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">entry</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,<br /></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 0, 0);">}<br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">10</span> <span style="color: rgb(0, 0, 0);">urlpatterns </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> patterns(</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">django.views.generic.list_detail</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,<br /></span><span style="color: rgb(0, 128, 128);">11</span> <span style="color: rgb(0, 0, 0);">    (r</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">^blog/$</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">object_list</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">, entry_dict),<br /></span><span style="color: rgb(0, 128, 128);">12</span> <span style="color: rgb(0, 0, 0);">    (r</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">^blog/(?P&lt;slug&gt;.*)/$</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">object_detail</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">, entry_dict),<br /></span><span style="color: rgb(0, 128, 128);">13</span> <span style="color: rgb(0, 0, 0);">)<br /></span><span style="color: rgb(0, 128, 128);">14</span> <span style="color: rgb(0, 0, 0);"></span></div>   然后就要修改项目目录下的urls.py了，在(r'^admin/(.*)', admin.site.root)之前添加：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">(r</span><span style="color: rgb(128, 0, 0);">''</span><span style="color: rgb(0, 0, 0);">, include(</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">djangonjython.blog.urls</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">)),</span></div>   接着就要添加模板文件了，在blog目录下创建templates/blog这样的目录，然后再里面添加entry_list.html和entry_detail.html两个文件，内容分别如下：<br />entry_list.html<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 128);">1</span> <span style="color: rgb(0, 0, 0);">{% if entry_list %}<br /></span><span style="color: rgb(0, 128, 128);">2</span> <span style="color: rgb(0, 0, 0);">    {% for entry in entry_list %}<br /></span><span style="color: rgb(0, 128, 128);">3</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">a </span><span style="color: rgb(255, 0, 0);">href</span><span style="color: rgb(0, 0, 255);">="/blog/{{ entry.slug }}"</span><span style="color: rgb(0, 0, 255);">&gt;&lt;</span><span style="color: rgb(128, 0, 0);">h3</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">{{ entry.title }}</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">h3</span><span style="color: rgb(0, 0, 255);">&gt;&lt;/</span><span style="color: rgb(128, 0, 0);">a</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"> Post at: {{ entry.create_at|date:"Y-b-d" }}</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">hr</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">4</span> <span style="color: rgb(0, 0, 0);">    {% endfor %}<br /></span><span style="color: rgb(0, 128, 128);">5</span> <span style="color: rgb(0, 0, 0);">{% endif %}</span></div>entry_detail.html<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 128);">1</span> <span style="color: rgb(0, 0, 0);">{% if entry %}<br /></span><span style="color: rgb(0, 128, 128);">2</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">span </span><span style="color: rgb(255, 0, 0);">style</span><span style="color: rgb(0, 0, 255);">="color: green;"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">{{ entry.title }}</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">span</span><span style="color: rgb(0, 0, 255);">&gt;&lt;</span><span style="color: rgb(128, 0, 0);">br</span><span style="color: rgb(0, 0, 255);">/&gt;&lt;</span><span style="color: rgb(128, 0, 0);">br</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">3</span> <span style="color: rgb(0, 0, 0);">    post by: </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">b</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">{{ entry.author.username }}</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">b</span><span style="color: rgb(0, 0, 255);">&gt;&lt;</span><span style="color: rgb(128, 0, 0);">br</span><span style="color: rgb(0, 0, 255);">/&gt;&lt;</span><span style="color: rgb(128, 0, 0);">br</span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">4</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div </span><span style="color: rgb(255, 0, 0);">style</span><span style="color: rgb(0, 0, 255);">="color: blue"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">{{ entry.content|safe }}</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">5</span> <span style="color: rgb(0, 0, 0);">{% endif %}</span></div>   完成了这些之后，就要告诉django，怎么处理了，也就是要修改settings.py了：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> os<br />PROJECT_ROOT </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> os.path.abspath(</span><span style="color: rgb(128, 0, 128);">__file__</span><span style="color: rgb(0, 0, 0);">)<br />TEMPLATE_DIRS </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (<br />    os.path.join(PROJECT_ROOT, </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">blog/templates</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">),<br />)</span></div>   添加前面两句，修改后面的TEMPLATE_DIRS，告诉django到哪里去找模板文件。<br />   重新启动服务器，输入http://localhost:8000/blog/，就可以看到一个简单的blog列表了，如果有的话。点击相应的标题，就会进入到具体的entry了。<br />   到这里位置，一个简单的blog就算是创建好了。我们的目的主要是要看他在其他的服务器上是否能够运行，好的，这里就要进行打包处理了。<br />   django-jython提供了一个war命令，会将我们的工程打包成war包，方便部署。不过django-jython有一个小小的bug。找到jython/Lib/site-packages/doj/manamgement/commands/war.py，在该文件的第228行，原来是：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> dest_relative_path[</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">] </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(128, 0, 0);">/</span><span style="color: rgb(128, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">:</span></div>   现在我们要将其改为：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> dest_relative_path[</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">] </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> os.path.sep:</span></div>   因为在windows下得到的是'\\'而不是'/'，所以执行的时候会出错，可能开发者没有在windows下进行测试，所以出现了这样的情况。<br />   接着，我们需要链接postgresql的jdbc包，大家可以在这里下载<a href="http://jdbc.postgresql.org/download/postgresql-8.3-603.jdbc4.jar">postgres-jdbc</a>。下载后，将其放在项目目录下，开始打包：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">jython manage.py war </span><span style="color: rgb(0, 0, 0);">--</span><span style="color: rgb(0, 0, 0);">include</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">java</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">libs</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">postgresql</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">8.3</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">603</span><span style="color: rgb(0, 0, 0);">.jdbc4.jar</span></div>   过一段时间，就可以在项目的上一级目录看到djangonjython.war<br />   到这里，java程序员就可以使用熟悉的java web server进行部署了！部署完成后，输入http://localhost:8080/djangonjython/blog/就可以进行访问了。<br />   这里给出一些在tomcat上运行的截图：<br /></font><div align="center"><font size="2" face="Courier New"><img src="http://www.blogjava.net/images/blogjava_net/glorywine/admin_page.PNG" alt="admin_page.PNG" width="519" border="0" height="489" /></font><br /></div><div align="center"><img src="http://www.blogjava.net/images/blogjava_net/glorywine/backend.PNG" alt="backend.PNG" width="769" border="0" height="574" /><br /></div><font size="2" face="Courier New">   怎么样，感觉还是不错吧。<br />   其实，Django on Jython还有很长的路要走，要支持更多的主流数据库，以及运行效率等问题。不过还是非常期待，希望能够快速的发展，毕竟Django的开发效率要远远高于Java。So let's look forward to it!<br /><br /><br /><br /><br /></font></div></div><img src ="http://www.blogjava.net/glorywine/aggbug/229275.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/glorywine/" target="_blank">glorywine</a> 2008-09-17 00:41 <a href="http://www.blogjava.net/glorywine/archive/2008/09/17/229275.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Django Docs</title><link>http://www.blogjava.net/glorywine/archive/2008/08/24/223987.html</link><dc:creator>glorywine</dc:creator><author>glorywine</author><pubDate>Sun, 24 Aug 2008 07:17:00 GMT</pubDate><guid>http://www.blogjava.net/glorywine/archive/2008/08/24/223987.html</guid><wfw:comment>http://www.blogjava.net/glorywine/comments/223987.html</wfw:comment><comments>http://www.blogjava.net/glorywine/archive/2008/08/24/223987.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/glorywine/comments/commentRss/223987.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/glorywine/services/trackbacks/223987.html</trackback:ping><description><![CDATA[       做Django开发, 经常需要查看docs, 这就需要我到官网上去浏览. 如果遇到网络不好, 页面打开十分缓慢, 非常痛苦.<br />       其实, 在django的svn repository里, 有相应的docs, 不过是txt格式的. 如果浏览这个, 当然会非常的别扭.<br />       今天看到, django对docs进行了重构, 现在大家可以将这些文件下载到本地, 然后进行编译, 生成相应的文档, 浏览起来会非常方便, 舒服.<br /><br />       好, 我们简单的看一看该如何操作:<br />1. 从svn库中checkout:<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">svn co http:</span><span style="color: rgb(0, 0, 0);">//</span><span style="color: rgb(0, 0, 0);">code.djangoproject.com</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">svn</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">django</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">trunk</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">docs</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);"> django_docs<br /></span></div>       这样, 在当前目录下就会有了django_docs了. 进去看一看, 恩, 重构后结构果然清晰多了,  过去是一股脑将所有的文件放在一起, 现在是分门别类, 不错.<br /><br />2. 安装Sphinx:<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">easy_install Sphinx</span></div>        当然前提是python中已经安装了easy_install, 如果没有, 大家google一下, 非常容易. <br />        熟悉python的朋友应该知道, Sphinx是非常好的一个工具, 可以将简单文本格式转换为html格式, 当然, 文本内容需要按照Sphinx的语法进行编写. Python现在的在线documents就是使用Sphinx进行编译的.感兴趣的朋友可以到<a href="http://sphinx.pocoo.org/">Sphinx</a>了解更多内容.<br /><br />3. 编译:<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">make html</span></div>        这里make提供了很多种格式, 因为我们只需要html, 所以加上这个选项就行了.<br />        到这里, 就完成了django_docs的编译工作, 在django_docs/_build/html下就是编译的结果. 重构后的文档的css也有了新的变化, 现在的非常像django_book的样式.<br />        OK, 以后我们就可以在本地进行文档的阅读了, 相信会给开发带来事半功倍的效果.<br />        <br />        这里我附上一份我编译好的, 供大家下载. <a href="/Files/glorywine/html.zip">django_docs<br /></a><img src ="http://www.blogjava.net/glorywine/aggbug/223987.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/glorywine/" target="_blank">glorywine</a> 2008-08-24 15:17 <a href="http://www.blogjava.net/glorywine/archive/2008/08/24/223987.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>