﻿<?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/pts/category/18194.html</link><description>editer by sun</description><language>zh-cn</language><lastBuildDate>Fri, 04 Jun 2010 06:42:52 GMT</lastBuildDate><pubDate>Fri, 04 Jun 2010 06:42:52 GMT</pubDate><ttl>60</ttl><item><title>[2]Django 笔记：已经看到Making queries</title><link>http://www.blogjava.net/pts/archive/2010/06/01/322499.html</link><dc:creator>pts</dc:creator><author>pts</author><pubDate>Tue, 01 Jun 2010 15:03:00 GMT</pubDate><guid>http://www.blogjava.net/pts/archive/2010/06/01/322499.html</guid><wfw:comment>http://www.blogjava.net/pts/comments/322499.html</wfw:comment><comments>http://www.blogjava.net/pts/archive/2010/06/01/322499.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/pts/comments/commentRss/322499.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pts/services/trackbacks/322499.html</trackback:ping><description><![CDATA[<pre><span class="n">有关select_related</span><span class="p">()、update、F()的内容不是太清晰。</span></pre>
<img src ="http://www.blogjava.net/pts/aggbug/322499.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pts/" target="_blank">pts</a> 2010-06-01 23:03 <a href="http://www.blogjava.net/pts/archive/2010/06/01/322499.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[1]  Django笔记：Django 入门</title><link>http://www.blogjava.net/pts/archive/2010/05/30/322276.html</link><dc:creator>pts</dc:creator><author>pts</author><pubDate>Sun, 30 May 2010 06:48:00 GMT</pubDate><guid>http://www.blogjava.net/pts/archive/2010/05/30/322276.html</guid><wfw:comment>http://www.blogjava.net/pts/comments/322276.html</wfw:comment><comments>http://www.blogjava.net/pts/archive/2010/05/30/322276.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/pts/comments/commentRss/322276.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pts/services/trackbacks/322276.html</trackback:ping><description><![CDATA[<pre><span class="k">from</span> <span class="nn">django.db</span> <span class="k">import</span> <span class="n">models</span><br />
<br />
<br />
<br />
<span class="k">class</span> <span class="nc">Poll</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span><br />
<br />
<span class="n">question</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mf">200</span><span class="p">)</span><br />
<br />
<span class="n">pub_date</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">DateTimeField</span><span class="p">(</span><span class="s">'date published'</span><span class="p">)</span><br />
<br />
<br />
<br />
<span class="k">class</span> <span class="nc">Choice</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span><br />
<br />
<span class="n">poll</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">ForeignKey</span><span class="p">(</span><span class="n">Poll</span><span class="p">)</span><br />
<br />
<span class="n">choice</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mf">200</span><span class="p">)</span><br />
<br />
<span class="n">votes</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">IntegerField</span><span class="p">()</span><br />
<br />
<br />
<br />
</pre>
安装Django<br />
<br />
<h2>建议安装python2.5及以上版本，但不建议使用python3.0。</h2>
数据库如果使用sqllite，python已经内建，不需另行安装，如果需要使用myslq或其他数据库，需要自行安装。<br />
<br />
接下来安装Django（在widnwos下）：<br />
1、从http://www.djangoproject.com/download/下载Django<br />
2、在windwos下使用python setup.py install 安装（我原想使用python setup.py develop安装，没成功），前提是设置好python环境和已安装setuptools。<br />
3、将python安装目录下lib\site-packages\django\bin\django-admin.py 复制到python安装目录下的\scripts\目录。<br />
<br />
下面可以测试一下，启动cmd窗口：<br />
C:\Documents and Settings\Administrator&gt;python<br />
&gt;&gt;&gt; import django<br />
&gt;&gt;&gt; django.VERSION<br />
(1, 2, 0, 'rc', 1)<br />
<br />
安装OK。开始创建第一个project吧。<br />
<br />
1、选定一个目录，启动cmd窗口：<br />
F:\temp&gt;django-admin.py startproject mysite2<br />
F:\temp&gt;<br />
这将在当前目录下新建一个project，名字为mysite2（注意不要使用"django"等保留字作为project名称），目录结构为：<br />
<br />
2010-05-30&nbsp; 13:29&nbsp;&nbsp;&nbsp; &lt;DIR&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .<br />
2010-05-30&nbsp; 13:29&nbsp;&nbsp;&nbsp; &lt;DIR&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ..<br />
2010-05-30&nbsp; 13:29&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 557 manage.py<br />
2010-05-30&nbsp; 13:29&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3,387 settings.py<br />
2010-05-30&nbsp; 13:29&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 561 urls.py<br />
2010-05-30&nbsp; 13:29&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 __init__.py<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4 个文件&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4,505 字节<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2 个目录 29,717,716,992 可用字节<br />
<ul class="simple">
    <li><tt class="docutils literal"><span class="pre">__init__.py</span></tt>:暂时是空的，标识这个目录是一个python package。</li>
    <li><tt class="docutils literal"><span class="pre">manage.py</span></tt>: Django的命令行工具集，使用方法：python manage.py ***<br />
    </li>
    <li><tt class="docutils literal"><span class="pre">settings.py</span></tt>: project 的配置文件</li>
    <li><tt class="docutils literal"><span class="pre">urls.py</span></tt>: project的url路径管理配置文件</li>
</ul>
先了解这么多吧，详细的文件内容单独再说。<br />
<br />
2、启动http server:<br />
F:\temp\mysite2&gt;python manage.py runserver<br />
Validating models...<br />
0 errors found<br />
<br />
Django version 1.2 rc 1, using settings 'mysite2.settings'<br />
Development server is running at http://127.0.0.1:8000/<br />
Quit the server with CTRL-BREAK.<br />
<br />
打开web browser，输入地址http://127.0.0.1:8000/，可以看到server已经启动了。当然，如果你希望换一个端口，可以使用：<span style="font-family: monospace;"><br />
</span>python manage.py runserver 端口号<br />
<br />
3、接着配置database：<br />
<p><span style="font-family: monospace;">打开</span><tt class="docutils literal"><span class="pre">settings.py<span style="font-family: sans-serif;">，在database节点下：</span></span></tt></p>
<ul>
    <li>
    <p class="first"><a class="reference external" href="http://docs.djangoproject.com/en/1.2/ref/settings/#setting-ENGINE"><tt class="xref docutils literal"><span class="pre">ENGINE</span></tt></a> <span style="font-family: monospace;">数据库引擎名称，可以是</span><tt class="docutils literal"><span class="pre">'django.db.backends.postgresql_psycopg2'</span></tt>或
    <tt class="docutils literal"><span class="pre">'django.db.backends.mysql'</span></tt> 或
    <tt class="docutils literal"><span class="pre">'django.db.backends.sqlite3'</span></tt></p>
    </li>
    <li>
    <p><a class="reference external" href="http://docs.djangoproject.com/en/1.2/ref/settings/#setting-NAME"><tt class="xref docutils literal"><span class="pre">NAME</span></tt></a>&nbsp; 数据库名称， 如果使用sqlite，这里就是db文件绝对路径，比如f:/temp/mysite/data.db</p>
    </li>
    <li>
    <p class="first"><a class="reference external" href="http://docs.djangoproject.com/en/1.2/ref/settings/#setting-USER"><tt class="xref docutils literal"><span class="pre">USER</span></tt></a> 数据库用户名，sqlite不需要</p>
    </li>
    <li>
    <p class="first"><a class="reference external" href="http://docs.djangoproject.com/en/1.2/ref/settings/#setting-PASSWORD"><tt class="xref docutils literal"><span class="pre">PASSWORD</span></tt></a> 密码，sqlite不需要</p>
    </li>
    <li>
    <p class="first"><a class="reference external" href="http://docs.djangoproject.com/en/1.2/ref/settings/#setting-HOST"><tt class="xref docutils literal"><span class="pre">HOST</span></tt></a> 数据库主机ip，sqlite不需要</p>
    </li>
</ul>
<p>建议使用sqlite。如果使用其他如PostgerSQL、MySQL等，在配置之前要确保先在数据库中已建立相关项目。<br />
</p>
在setting.py中的INSTALLED_APPS节点下，默认有以下一个APP：<br />
&nbsp;&nbsp;&nbsp; 'django.contrib.auth',用户认证<br />
&nbsp;&nbsp;&nbsp; 'django.contrib.contenttypes',内容管理?<br />
&nbsp;&nbsp;&nbsp; 'django.contrib.sessions',session控制<br />
&nbsp;&nbsp;&nbsp; 'django.contrib.sites',多site管理<br />
如果用不到该app，可以注释掉，这将不在database中建立相关管理tables。然后使用：<br />
python manage.py syncdb<br />
建立相应的tables。<br />
<br />
4、在mysite2目录下，新建一个自己的app：<br />
python manage.py startapp polls<br />
将新建一个polls目录，内容如下：<br />
2010-05-30&nbsp; 14:07&nbsp;&nbsp;&nbsp; &lt;DIR&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .<br />
2010-05-30&nbsp; 14:07&nbsp;&nbsp;&nbsp; &lt;DIR&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ..<br />
2010-05-30&nbsp; 14:07&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 60 models.py<br />
2010-05-30&nbsp; 14:07&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 537 tests.py<br />
2010-05-30&nbsp; 14:07&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 27 views.py<br />
2010-05-30&nbsp; 14:07&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 __init__.py<br />
<br />
5、创建models：<br />
编辑models.py,内容如下：<br />
<pre><span class="k">from</span> <span class="nn">django.db</span> <span class="k">import</span> <span class="n">models</span><br />
<br />
<span class="k">class</span> <span class="nc">Poll</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span><br />
<br />
<span class="n">question</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mf">200</span><span class="p">)</span><br />
<br />
<span class="n">pub_date</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">DateTimeField</span><span class="p">(</span><span class="s">'date published'</span><span class="p">)</span><br />
<br />
<span class="k">class</span> <span class="nc">Choice</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span><br />
<br />
<span class="n">poll</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">ForeignKey</span><span class="p">(</span><span class="n">Poll</span><span class="p">)</span><br />
<br />
<span class="n">choice</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mf">200</span><span class="p">)</span><br />
<br />
<span class="n">votes</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">IntegerField</span><span class="p">()</span><br />
<br />
这里有两个model，Poll和Choice，还存在一个one Poll to many Choice关系。<br />
<br />
在setting.py 中将polls 加入到installed app 节点中，然后使用python manage.py syncdb 将在database中新建相应的tables。<span style="font-family: sans-serif;">table name 分别是：<br />
<br />
polls_poll,polls_choice。<br />
<br />
当然还有其他一些manage command:<br />
<br />
</span></pre>
<ul class="simple">
    <li><a class="reference external" href="http://docs.djangoproject.com/en/dev/ref/django-admin/#djadmin-validate"><tt class="xref docutils literal"><span class="pre">python</span> <span class="pre">manage.py</span> <span class="pre">validate</span></tt></a> -- 校验model内容是否正确<br />
    </li>
    <li><a class="reference external" href="http://docs.djangoproject.com/en/dev/ref/django-admin/#djadmin-sqlcustom"><tt class="xref docutils literal"><span class="pre">python</span> <span class="pre">manage.py</span> <span class="pre">sqlcustom</span> <span class="pre">polls</span></tt></a> -- 输出polls app中的model相关的sql相关语句<br />
    </li>
    <li><a class="reference external" href="http://docs.djangoproject.com/en/dev/ref/django-admin/#djadmin-sqlclear"><tt class="xref docutils literal"><span class="pre">python</span> <span class="pre">manage.py</span> <span class="pre">sqlclear</span> <span class="pre">polls</span></tt></a> -- 输出删除table的相关sql</li>
    <li><a class="reference external" href="http://docs.djangoproject.com/en/dev/ref/django-admin/#djadmin-sqlindexes"><tt class="xref docutils literal"><span class="pre">python</span> <span class="pre">manage.py</span> <span class="pre">sqlindexes</span> <span class="pre">polls</span></tt></a> -- 输出建立index的相关sql</li>
    <li><a class="reference external" href="http://docs.djangoproject.com/en/dev/ref/django-admin/#djadmin-sqlall"><tt class="xref docutils literal"><span class="pre">python</span> <span class="pre">manage.py</span> <span class="pre">sqlall</span> <span class="pre">polls</span></tt></a> -- <span style="font-family: monospace;">是</span><a class="reference external" href="http://docs.djangoproject.com/en/dev/ref/django-admin/#djadmin-sql"><tt class="xref docutils literal"><span class="pre">sql</span></tt></a>, <a class="reference external" href="http://docs.djangoproject.com/en/dev/ref/django-admin/#djadmin-sqlcustom"><tt class="xref docutils literal"><span class="pre">sqlcustom</span></tt></a>, and
    <a class="reference external" href="http://docs.djangoproject.com/en/dev/ref/django-admin/#djadmin-sqlindexes"><tt class="xref docutils literal"><span class="pre">sqlindexes</span></tt></a> 输出内容的组合<br />
    </li>
</ul>
<pre>6、使用django shell：<br />
<br />
python manage.py shell<br />
<br />
这个cmd背后做了两件事：一是将mysite2加入到sys.path中去；二是新建了<tt class="docutils literal"><span class="pre">DJANGO_SETTINGS_MODULE环境变量，可以引用settings.py中的配置内容。<br />
<br />
接下来就可以测试了。<br />
<br />
</span></tt></pre>
<img src ="http://www.blogjava.net/pts/aggbug/322276.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pts/" target="_blank">pts</a> 2010-05-30 14:48 <a href="http://www.blogjava.net/pts/archive/2010/05/30/322276.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>计划开始翻译Django doc</title><link>http://www.blogjava.net/pts/archive/2010/05/30/322271.html</link><dc:creator>pts</dc:creator><author>pts</author><pubDate>Sun, 30 May 2010 05:04:00 GMT</pubDate><guid>http://www.blogjava.net/pts/archive/2010/05/30/322271.html</guid><wfw:comment>http://www.blogjava.net/pts/comments/322271.html</wfw:comment><comments>http://www.blogjava.net/pts/archive/2010/05/30/322271.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/pts/comments/commentRss/322271.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pts/services/trackbacks/322271.html</trackback:ping><description><![CDATA[想想工作量很大，因此准备按自己的理解要点翻译。<br />
坚持就是胜利！<br />
<br />
BTW：如果有好的在线翻译平台，哪位知我一声。<br />
<img src ="http://www.blogjava.net/pts/aggbug/322271.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pts/" target="_blank">pts</a> 2010-05-30 13:04 <a href="http://www.blogjava.net/pts/archive/2010/05/30/322271.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>make django project environment</title><link>http://www.blogjava.net/pts/archive/2008/04/22/194848.html</link><dc:creator>pts</dc:creator><author>pts</author><pubDate>Tue, 22 Apr 2008 10:12:00 GMT</pubDate><guid>http://www.blogjava.net/pts/archive/2008/04/22/194848.html</guid><wfw:comment>http://www.blogjava.net/pts/comments/194848.html</wfw:comment><comments>http://www.blogjava.net/pts/archive/2008/04/22/194848.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/pts/comments/commentRss/194848.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pts/services/trackbacks/194848.html</trackback:ping><description><![CDATA[import sys,os <br />
sys.path.append('/path/to/root/of/django/projects/') <br />
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
<img src ="http://www.blogjava.net/pts/aggbug/194848.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pts/" target="_blank">pts</a> 2008-04-22 18:12 <a href="http://www.blogjava.net/pts/archive/2008/04/22/194848.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在django中引用静态文件</title><link>http://www.blogjava.net/pts/archive/2008/01/19/176505.html</link><dc:creator>pts</dc:creator><author>pts</author><pubDate>Sat, 19 Jan 2008 09:59:00 GMT</pubDate><guid>http://www.blogjava.net/pts/archive/2008/01/19/176505.html</guid><wfw:comment>http://www.blogjava.net/pts/comments/176505.html</wfw:comment><comments>http://www.blogjava.net/pts/archive/2008/01/19/176505.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.blogjava.net/pts/comments/commentRss/176505.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pts/services/trackbacks/176505.html</trackback:ping><description><![CDATA[要在django的tempalte file中引用css、js、gif等静态文件，首先一条setting.py中DEBUG开关打开。<br />
1、在project目录下建立一个存放静态文件的目录，如：medias<br />
2、在url.py patterns中增加一行：<br />
&nbsp;&nbsp; (r'^site_media/(?P&lt;path&gt;.*)$','django.views.static.serve',{'document_root':settings.STATIC_PATH}),<br />
&nbsp;&nbsp; 还要from django.conf import setting<br />
3、在setting.py中加入一行：<br />
&nbsp;&nbsp; STATIC_PATH='./medias'<br />
<br />
如此设置后，就可以在template file 中引用media中存放的静态文件了，如：<br />
&nbsp;&nbsp; &lt;img src='/site_media/django.gif'&gt;<br />
<br />
详细可见<a href="http://www.donews.net/limodou">limodou</a>写的<a href="http://www.woodpecker.org.cn/obp/django/django-stepbystep/newtest/doc/tut09.html">django step by step</a><br />
<br />
<br />
<p class="poweredbyperformancing">Powered by <a href="http://scribefire.com/">ScribeFire</a>.</p>
<img src ="http://www.blogjava.net/pts/aggbug/176505.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pts/" target="_blank">pts</a> 2008-01-19 17:59 <a href="http://www.blogjava.net/pts/archive/2008/01/19/176505.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ulipad的几个技巧</title><link>http://www.blogjava.net/pts/archive/2007/12/25/170404.html</link><dc:creator>pts</dc:creator><author>pts</author><pubDate>Tue, 25 Dec 2007 14:24:00 GMT</pubDate><guid>http://www.blogjava.net/pts/archive/2007/12/25/170404.html</guid><wfw:comment>http://www.blogjava.net/pts/comments/170404.html</wfw:comment><comments>http://www.blogjava.net/pts/archive/2007/12/25/170404.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/pts/comments/commentRss/170404.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pts/services/trackbacks/170404.html</trackback:ping><description><![CDATA[1、在doc目录下有几个帮助文档，比较有用的是english写的关于自动完成功能介绍、config.ini文件配置说明、代码片段的使用<br />
2、在安装目录/conf下有acp文件，是设计到代码自动完成功能的，可以自定义，且一个acp文件可以引用其他acp文件：<br />
[include]<br />
1=django_py.acp<br />
2=epydoc.acp<br />
（赞！）<br />
3、在acp文件中的定义的如：<br />
(^\s*)cdef&lt;space&gt; = "\\1def ${1:}(self, ${2:}):\n\t${0}"<br />
在几个${*:}之间可以用tab键直接转移输入位置。<br />
4、在acp文件中使用&#8220;[&#8221;的自动完成：<br />
[autostring_append]<br />
[="!^]"<br />
我想在输入[后自动补为[]，由于[被定义为了acp文件中的一个key，因此应该这样定义：<br />
[autostring_append]<br />
&lt;square&gt;="!^]"<br />
这个questtion还得到了<a href="http://groups.google.com/group/ulipad/t/5677e6c380ff052d">limodou的回答</a>，非常感谢！<br />
更多功能上<a href="http://groups.google.com/group/ulipad">ulipad的google组</a><br />
<br />
<br />
<p class="poweredbyperformancing">Powered by <a href="http://scribefire.com/">ScribeFire</a>.</p>
<img src ="http://www.blogjava.net/pts/aggbug/170404.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pts/" target="_blank">pts</a> 2007-12-25 22:24 <a href="http://www.blogjava.net/pts/archive/2007/12/25/170404.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>django 中测试csv</title><link>http://www.blogjava.net/pts/archive/2007/01/05/92115.html</link><dc:creator>pts</dc:creator><author>pts</author><pubDate>Fri, 05 Jan 2007 13:09:00 GMT</pubDate><guid>http://www.blogjava.net/pts/archive/2007/01/05/92115.html</guid><wfw:comment>http://www.blogjava.net/pts/comments/92115.html</wfw:comment><comments>http://www.blogjava.net/pts/archive/2007/01/05/92115.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/pts/comments/commentRss/92115.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pts/services/trackbacks/92115.html</trackback:ping><description><![CDATA[按照<a href="http://www.woodpecker.org.cn/obp/django/django-stepbystep/newtest/doc/tut04.html">Django Step by Step</a>中介绍的步骤，编辑csv_test.py时,如果使用<br /><pre class="literal-block">address = [<br />    ('张三', '地址一'),<br />    ('李四', '地址二')<br />    ]<br /><br />那么可以在template文件csv.html中使用<br />row.0....方式引用。<br />由于此前我从上一讲复制了address的定义：<br />address=[<br />    {'name':'张三','address':'洛阳栾川'},<br />    {'name':'里斯','address':'整整络散结'}<br />    ]<br />所以使用row.0方式引用时，django不会报错，但就是什么内容也没有，使用row.name方式应用后正常。<br /></pre><br /><img src ="http://www.blogjava.net/pts/aggbug/92115.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pts/" target="_blank">pts</a> 2007-01-05 21:09 <a href="http://www.blogjava.net/pts/archive/2007/01/05/92115.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Django DOC of Database API reference</title><link>http://www.blogjava.net/pts/archive/2006/12/10/86752.html</link><dc:creator>pts</dc:creator><author>pts</author><pubDate>Sun, 10 Dec 2006 12:44:00 GMT</pubDate><guid>http://www.blogjava.net/pts/archive/2006/12/10/86752.html</guid><wfw:comment>http://www.blogjava.net/pts/comments/86752.html</wfw:comment><comments>http://www.blogjava.net/pts/archive/2006/12/10/86752.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/pts/comments/commentRss/86752.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pts/services/trackbacks/86752.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Database API referenceThis covers Django version 0.95 and the development version. Old docs: 0.90, 0.91Once you've created your data models, Django automatically gives you a database-abstraction API t...&nbsp;&nbsp;<a href='http://www.blogjava.net/pts/archive/2006/12/10/86752.html'>阅读全文</a><img src ="http://www.blogjava.net/pts/aggbug/86752.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pts/" target="_blank">pts</a> 2006-12-10 20:44 <a href="http://www.blogjava.net/pts/archive/2006/12/10/86752.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Django Generic Views: CRUD</title><link>http://www.blogjava.net/pts/archive/2006/12/08/86476.html</link><dc:creator>pts</dc:creator><author>pts</author><pubDate>Fri, 08 Dec 2006 15:45:00 GMT</pubDate><guid>http://www.blogjava.net/pts/archive/2006/12/08/86476.html</guid><wfw:comment>http://www.blogjava.net/pts/comments/86476.html</wfw:comment><comments>http://www.blogjava.net/pts/archive/2006/12/08/86476.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/pts/comments/commentRss/86476.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pts/services/trackbacks/86476.html</trackback:ping><description><![CDATA[
		<div id="primarycontent">
				<div>
						<div class="item entry" id="post-3743">
								<div class="itemtext">
										<strong>
												<div class="itemhead">
														<h3>
																<a title="Permanent Link to &quot;Django Generic Views: CRUD&quot;" href="http://www.postneo.com/2005/08/17/django-generic-views-crud" rel="bookmark">Django Generic Views: CRUD</a>
														</h3>
														<small class="metadata">
																<span class="chronodata">Published by <a title="Posts by Matt Croydon" href="http://www.postneo.com/author/site-admin/">Matt Croydon</a> August 17th, 2005 in <a title="View all posts in Projects" href="http://www.postneo.com/categories/projects/" rel="category tag">Projects</a>, <a title="View all posts in Python" href="http://www.postneo.com/categories/python/" rel="category tag">Python</a>, <a title="View all posts in Django" href="http://www.postneo.com/categories/python/django/" rel="category tag">Django</a></span>
																<br />
														</small>
														<br />Note:</div>
										</strong> I’ve not yet updated this to reflect the new model syntax. For the time being <a href="http://postneo.com/projects/django/tasks.py.txt">you can take a look at the new model syntax for tasks here</a>.</div>
								<p>There are lots of gems buried in <a href="http://www.djangoproject.com/">Django</a> that are slowly coming to light. <a href="http://www.djangoproject.com/documentation/generic_views/">Generic views</a> and specifically the CRUD (create, update, delete) generic views are extremely powerful but underdocumented. This brief tutorial will show you how to make use of CRUD generic views in your Django application.</p>
								<p>One of my first encounters with <a href="http://www.rubyonrails.com/">Rails</a> was <a href="http://manuals.rubyonrails.com/read/book/7">the simple todo list tutorial</a> which managed to relate lots of useful information by creating a simple yet useful application. While I will do my best to point out interesting and useful things along the way, it is probably best that you be familiar with <a href="http://www.djangoproject.com/documentation/">the official Django tutorials</a>. Now would also probably be a good time to mention that this tutorial works for me using <a href="http://www.mysql.com/">MySQL</a> and revision 524. Django is under constant development, so things may change. I’ll do my best to keep up with changes.</p>
								<h3>Getting Started</h3>
								<p>As with all Django projects, the best place to start is to start with <code>django-admin.py startproject todo</code>. Make sure that the directory you created your project in is in your <code>PYTHONPATH</code>, then edit <code>todo/settings/main.py</code> to point to the database of your choice. Now would be a good time to set your <code>DJANGO_SETTINGS_MODULE</code> to <code>"todo.settings.main"</code>. Next move to your <code>apps/</code> dir and create a new application: <code>django-admin.py startapp tasks</code> and <code>django-admin.py init</code>. The initial setup process is covered in much more detail in <a href="http://www.djangoproject.com/documentation/tutorial1/">tutorial 1</a>.</p>
								<h3>The Model</h3>
								<p>Now that we have the project set up, let’s take a look at our rather simple model (<code>todo/apps/tasks/models/tasks.py</code>):</p>
								<p>
										<code>
										</code>
								</p>
								<pre>from django.core import meta

# Create your models here.

class Task(meta.Model):
  fields = (
    meta.CharField('title', maxlength=200),
    meta.TextField('description'),
    meta.DateTimeField('create_date', 'date created'),
    meta.DateTimeField('due_date', 'date due'),
    meta.BooleanField('done'),
  )

  admin = meta.Admin(
    list_display = ( 'title', 'description', 'create_date', 'due_date', 'done' ),
    search_fields = ['title', 'description'],
    date_hierarchy = 'due_date',
  )

  def __repr__(self):
    return self.title</pre>
								<p>
								</p>
								<p>The model is short and sweet, storing a title, description, two dates, and if the task is done or not. To play with your model in the admin, add the following to <code>INSTALLD_APPS</code> in <code>todo/settings/main.py</code>: <code>'todo.apps.tasks',</code></p>
								<p>Feel free to play around with your model using the admin site. For details, <a href="http://www.djangoproject.com/documentation/tutorial2/">see tutorial 2</a>.</p>
								<h3>URL Configuration</h3>
								<p>Now let’s configure our URLs. We’ll fill in the code behind these URLs as we go. I edited <code>todo/settings/urls/main.py</code> directly, but you’re probably best off decoupling your URLs to your specific app as mentiond in <a href="http://www.djangoproject.com/documentation/tutorial3/">tutorial 3</a>.</p>
								<p>
										<code>
										</code>
								</p>
								<pre>from django.conf.urls.defaults import *

info_dict = {
  'app_label': 'tasks',
  'module_name': 'tasks',
}

urlpatterns = patterns('',
  (r'^tasks/?$', 'todo.apps.tasks.views.tasks.index'),
  (r'^tasks/create/?$', 'django.views.generic.create_update.create_object',
  dict(info_dict, post_save_redirect="/tasks/") ),
  (r'^tasks/update/(?P&lt;object_id&gt;d+)/?$',
  'django.views.generic.create_update.update_object', info_dict),
  (r'^tasks/delete/(?P&lt;object_id&gt;d+)/?$',
  'django.views.generic.create_update.delete_object',
  dict(info_dict, post_delete_redirect="/tasks/new/") ),
  (r'^tasks/complete/(?P&lt;object_id&gt;d+)/?$',
  'todo.apps.tasks.views.tasks.complete'),
)</pre>
								<p>
								</p>
								<p>Note: I had to alter the formatting of the urlpatterns in order to make them fit. It looks a lot better in <a href="http://postneo.com/projects/django/urlpatterns.txt">its original formatting</a>.</p>
								<p>We use the <code>info_dict</code> to pass information about our application and module to the generic view handlers . The CRUD generic views need only provide these two pieces of information, but some generic views need more. See <a href="http://www.djangoproject.com/documentation/generic_views/">the generic views documentation</a> for an explanation.</p>
								<p>Let’s look at each of these URLs one at a time, along with the code behind them.</p>
								<h3>Index</h3>
								<p>
										<code>(r'^tasks/?$', 'todo.apps.tasks.views.tasks.index'),</code>
								</p>
								<p>This points to our index view, which is an index function in <code>todo/apps/tasks/views/tasks.py</code>:</p>
								<p>
										<code>
										</code>
								</p>
								<pre>from django.core import template_loader
from django.core.extensions import DjangoContext as Context
from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect
from django.models.tasks import tasks
from django.core.exceptions import Http404

def index(request):
  notdone_task_list = tasks.get_list(order_by=['-due_date'], done__exact=False)
  done_task_list = tasks.get_list(order_by=['-due_date'], done__exact=True)
  t = template_loader.get_template('tasks/index')
  c = Context(request, {
    'notdone_tasks_list': notdone_task_list,
    'done_tasks_list': notdone_task_list,
  })
  return HttpResponse(t.render(c))</pre>
								<p>
								</p>
								<p>This view creates two lists for us to work with in our template, <code>notdone_tasks_list</code> is (not suprisingly) a list of tasks that are not done yet. Similarly, <code>done_tasks_list</code> contains a list of tasks that have been completed. We will use the template <code>tasks/index.html</code> to render this view.</p>
								<p>Make sure that you have a template directory defined in todo.settings.main (this refers to <code>todo/settings/main.py</code>). Here’s mine:</p>
								<p>
										<code>
										</code>
								</p>
								<pre>TEMPLATE_DIRS = (
 "/home/mcroydon/django/todo/templates",
)</pre>
								<p>
								</p>
								<p>Now let’s take a look at the template that I’m using for the index:</p>
								<p>
										<code>
										</code>
								</p>
								<pre>{% if notdone_tasks_list %}
    &lt;p&gt;Pending Tasks:&lt;/p&gt;
    &lt;ul&gt;
    {% for task in notdone_tasks_list %}
        &lt;li&gt;{{ task.title }}: {{ task.description }} &lt;br/&gt;
          Due {{ task.due_date }} &lt;br/&gt;
          &lt;a href="/tasks/update/{{ task.id }}/"&gt;Update&lt;/a&gt;
          &lt;a href="/tasks/complete/{{ task.id }}/"&gt;Complete&lt;/a&gt;
        &lt;/li&gt;
    {% endfor %}
    &lt;/ul&gt;
{% else %}
    &lt;p&gt;No tasks pending.&lt;/p&gt;
{% endif %}
    &lt;p&gt;Completed Tasks:&lt;/p&gt;
    &lt;ul&gt;
{% if done_tasks_list %}
    {% for task in done_tasks_list %}
        &lt;li&gt;{{ task.title }}: {{ task.description }} &lt;br/&gt;
          &lt;a href="/tasks/delete/{{ task.id }}/"&gt;Delete&lt;/a&gt;
        &lt;/li&gt;
    {% endfor %}
    &lt;/ul&gt;
{% else %}
    &lt;p&gt;No completed pending.&lt;/p&gt;
{% endif %}
&lt;p&gt;&lt;a href="/tasks/create/"&gt;Add a task&lt;/a&gt;&lt;/p&gt;</pre>
								<p>
								</p>
								<p>Don’t let this index scare you, it’s just a little bit of logic, a little looping, and some links to other parts of the application. See <a href="http://www.djangoproject.com/documentation/templates/">the template authoring guide</a> if you have questions. Here’s a picture to give you a better idea as to how the above barebones template renders in <a href="http://www.mozilla.org/products/firefox/">Firefox</a>:</p>
								<p align="center">
										<a href="http://postneo.com/pix/tasks_index.png">
												<img alt="Tasks thumbnail" src="http://postneo.com/pix/tasks_index_tn.png" border="0" />
										</a>
								</p>
								<h3>Create Generic View</h3>
								<p>Now let’s take a look at the following URL pattern:</p>
								<p>
										<code>(r'^tasks/create/?$', 'django.views.generic.create_update.create_object', dict(info_dict, post_save_redirect="/tasks/") ),</code>
								</p>
								<p>There’s a lot of magic going on here that’s going to make your life really easy. First off, we’re going to call the <code>create_object</code> generic view every time we visit <code>/tasks/create/</code>. If we arrive there with a <code>GET</code> request, the generic view displays a form. Specifically it’s looking for <code>module_name_form.html</code>. In our case it will be looking for <code>tasks_form</code>. It knows what model to look for because of the information we gave it in <code>info_dict</code>. If however we reach this URL via a <code>POST</code>, the <code>create_object</code> generic view will create a new object for us and then redirect us to the URL of our choice (as long as we give it a <code>post_save_redirect</code>).</p>
								<p>Here’s the template that I am using for <code>tasks_form.html</code>:</p>
								<p>
										<code>
										</code>
								</p>
								<pre>{% block content %}

{% if object %}
&lt;h1&gt;Update task:&lt;/h1&gt;
{% else %}
&lt;h1&gt;Create a Task&lt;/h1&gt;
{% endif %}

{% if form.has_errors %}
&lt;h2&gt;Please correct the following error{{ form.errors|pluralize }}:&lt;/h2&gt;
{% endif %}

&lt;form method="post" action="."&gt;
&lt;p&gt;&lt;label for="id_title"&gt;Title:&lt;/label&gt; {{ form.title }}
{% if form.title.errors %}*** {{ form.title.errors|join:", " }}{% endif %}&lt;/p&gt;
&lt;p&gt;&lt;label for="id_description"&gt;Description:&lt;/label&gt; {{ form.description }}
{% if form.description.errors %}*** {{ form.description.errors|join:", " }}{% endif %}&lt;/p&gt;
&lt;p&gt;&lt;label for="id_create_date_date"&gt;Create Date:&lt;/label&gt; {{ form.create_date_date }}
{% if form.create_date_date.errors %}*** {{ form.create_date_date.errors|join:", " }}{% endif %}&lt;/p&gt;
&lt;p&gt;&lt;label for="id_create_date_time"&gt;Create Time:&lt;/label&gt; {{ form.create_date_time }}
{% if form.create_date_time.errors %}*** {{ form.create_date_time.errors|join:", " }}{% endif %}&lt;/p&gt;
&lt;p&gt;&lt;label for="id_due_date_date"&gt;Due Date:&lt;/label&gt; {{ form.due_date_date }}
{% if form.due_date_date.errors %}*** {{ form.due_date_date.errors|join:", " }}{% endif %}&lt;/p&gt;
&lt;p&gt;&lt;label for="id_due_date_time"&gt;Due Time:&lt;/label&gt; {{ form.due_date_time }}
{% if form.due_date_time.errors %}*** {{ form.due_date_time.errors|join:", " }}{% endif %}&lt;/p&gt;
&lt;p&gt;&lt;label for="id_done"&gt;Done:&lt;/label&gt; {{ form.done }}
{% if form.done.errors %}*** {{ form.done.errors|join:", " }}{% endif %}&lt;/p&gt;
&lt;input type="submit" /&gt;
&lt;/form&gt;
&lt;!--
This is a lifesaver when debugging!
&lt;p&gt; {{ form.error_dict }} &lt;/p&gt;
--&gt;

{% endblock %}</pre>
								<p>
								</p>
								<p>Here’s what the create template looks like rendered:</p>
								<p align="center">
										<a href="http://postneo.com/pix/tasks_create.png">
												<img alt="Create Tasks" src="http://postneo.com/pix/tasks_create_tn.png" border="0" />
										</a>
								</p>
								<p>If we fill out the form without the proper (or correctly formatted) information, we’ll get an error:</p>
								<p align="center">
										<a href="http://postneo.com/pix/tasks_create_error.png">
												<img alt="Create Tasks" src="http://postneo.com/pix/tasks_create_error_tn.png" border="0" />
										</a>
								</p>
								<h3>Update</h3>
								<p>
										<code>(r'^tasks/update/(?P&lt;object_id&gt;\d+)/?$', 'django.views.generic.create_update.update_object', info_dict),</code>
								</p>
								<p>This URL pattern handles updates. The beautiful thing is it sends requests to <code>tasks_form.html</code>, so with a little logic, 90% of the form can be exactly the same as the create form. If we go to <code>/tasks/create/</code>, we get the blank form. If we visit <code>/tasks/update/1/</code> we will go to the same form but it will be prepopulated with the data from the task with the ID of 1. Here’s the logic that I used to change the header:</p>
								<p>
										<code>
										</code>
								</p>
								<pre>{% if object %}
&lt;h1&gt;Update task:&lt;/h1&gt;
{% else %}
&lt;h1&gt;Create a Task&lt;/h1&gt;
{% endif %}</pre>
								<p>
								</p>
								<p>So if there’s no object present, we’re creating. If there’s an object present, we’re updating. Same form. Pretty cool.</p>
								<p>
										<strong>Warning:</strong> It looks like form.create_date_date and form.create_date_time have broken between the time I wrote this and wrote it up. This form will not prepopulate the form with the stored information. There’s a ticket for this, and I’ll update as neccesary when it has been fixed.</p>
								<h3>Delete</h3>
								<p>Here’s the URL pattern to delte a task:</p>
								<p>
										<code>(r'^tasks/delete/(?P&lt;object_id&gt;\d+)/?$', 'django.views.generic.create_update.delete_object', dict(info_dict, post_delete_redirect="/tasks/new/") ),</code>
								</p>
								<p>There’s another little Django gem in the delete function. If we end up at <code>/tasks/delete/1</code> using a <code>GET</code> request, Django will automatically send us to the <code>tasks_form_delete.html</code> template. This allows us to make sure that the user <strong>really</strong> wanted to delete the task. here’s my very simple <code>tasks_form_delete.html</code> template:</p>
								<p>
										<code>
										</code>
								</p>
								<pre>&lt;form method="post" action="."&gt;
&lt;p&gt;Are you sure?&lt;/p&gt;
&lt;input type="submit" /&gt;
&lt;/form&gt;</pre>
								<p>
								</p>
								<p>Once this form is submitted, the actual delete takes place and we are redirected to the main index page (because we set <code>post_delete_redirect</code>.</p>
								<h3>CRUD Generic Views And the Rest of Your Application</h3>
								<p>That pretty much covers the basics of the CRUD generic views. The great thing about generic views is that you can use them along side your custom views. There’s no need to do a ton of custom programming for list/detail, date-based, or CRUD since those generic views are available to you. Because we set up our URL patterns, we can make sure that we craft URLs that look pretty and make sense.</p>
								<p>For my sample tasks application I decided that I wanted to create links that would immediately set a task as complete and then redirect to the index. This is pretty much trivial and can be accomplished by adding the following URL pattern and backing it up with the appropriate view. Here’s the pattern:</p>
								<p>
										<code>(r'^tasks/complete/(?P&lt;object_id&gt;\d+)/?$', 'todo.apps.tasks.views.tasks.complete'),</code>
								</p>
								<p>And here’s the view that goes along with it (from <code>todo/apps/tasks/models/tasks.py</code>):</p>
								<p>
										<code>
										</code>
								</p>
								<pre>def complete(request, object_id):
  try:
    t = tasks.get_object(pk=object_id)
  except:
    # do something better than this
    raise Http404
  try:
    t.done=True
    t.save()
    return HttpResponseRedirect('/tasks/')
  except:
    # do something better than this
    raise Http404</pre>
								<p>
								</p>
								<p>I do plan to actually handle errors and respond accordingly, but it was late last night and I just wanted to see it work (and it does).</p>
								<h3>Conclusion</h3>
								<p>Django rocks. Generic views rock. The framework and specifically the generic views make your life easy. My little tasks app took a few hours to put together, but a significant portion of that was reading up on the documentation, trying to figure out generic views using the existing docs and reading the source, and of course pestering the DjangoMasters about generic views and other stuff on #django (thanks all).</p>
								<p>I hope this overview of CRUD generic views helps, but if anything confuses you, don’t hesitate to comment or get in touch with me (matt at ooiio dot com). Also expect to see updates to this tutorial as APIs change and I get a little more time to clean up my code.</p>
								<p>Feel free to download and play with my little todo app: <a href="http://postneo.com/projects/django/todo-tutorial.tar.gz">todo-tutorial.tar.gz</a> or <a href="http://postneo.com/projects/django/todo-tutorial.zip">todo-tutorial.zip</a>. Consider them released under a <a href="http://www.opensource.org/licenses/bsd-license.php">BSD-style license</a>. Above all, don’t sue me.</p>
						</div>
						<!--
				<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
	    xmlns:dc="http://purl.org/dc/elements/1.1/"
	    xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
		<rdf:Description rdf:about="http://www.postneo.com/2005/08/17/django-generic-views-crud"
    dc:identifier="http://www.postneo.com/2005/08/17/django-generic-views-crud"
    dc:title="Django Generic Views: CRUD"
    trackback:ping="http://www.postneo.com/2005/08/17/django-generic-views-crud/trackback/" />
</rdf:RDF>				-->
				</div>
		</div>
		<!-- You can start editing here. -->
		<hr />
		<div class="comments">
				<h4>
						<span id="comments">24</span> Responses to “Django Generic Views: CRUD”</h4>
				<div class="metalinks">
						<span class="commentsrsslink">
								<a href="http://www.postneo.com/2005/08/17/django-generic-views-crud/feed/">Feed for this Entry</a>
						</span>
						<span class="trackbacklink">
								<a title="Copy this URI to trackback this entry." href="http://www.postneo.com/2005/08/17/django-generic-views-crud/trackback/">Trackback Address</a>
						</span>
				</div>
				<ol id="commentlist">
						<li class="item" id="comment-7129">
								<a class="counter" title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-7129">1</a>
								<span class="commentauthor">Steve</span>
								<small class="commentmetadata">
										<a title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-7129">Aug 17th, 2005 at 3:34 pm</a>
								</small>
								<div class="itemtext">
										<p>What would you think about making a screencast, a la Rails? That was a lot of Python to read, and I ended up skipping over it pretty quickly. </p>
								</div>
						</li>
						<li class="item" id="comment-7135">
								<a class="counter" title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-7135">2</a>
								<span class="commentauthor">
										<a href="http://www.jengajam.com/" rel="external nofollow">Dagur</a>
								</span>
								<small class="commentmetadata">
										<a title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-7135">Aug 17th, 2005 at 4:56 pm</a>
								</small>
								<div class="itemtext">
										<p>Cool stuff, but I noticed that the pluralize filter doesn’t work (see screenshot) </p>
								</div>
						</li>
						<li class="authorcomment item" id="comment-7137">
								<a class="counter" title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-7137">3</a>
								<span class="commentauthor">
										<a href="http://postneo.com/" rel="external nofollow">Matt Croydon</a>
								</span>
								<small class="commentmetadata">
										<a title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-7137">Aug 17th, 2005 at 5:36 pm</a>
								</small>
								<div class="itemtext">
										<p>Dagur,</p>
										<p>Yeah I noticed that but forgot to investigate it. I’ll let you know what I find out. </p>
								</div>
						</li>
						<li class="authorcomment item" id="comment-7138">
								<a class="counter" title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-7138">4</a>
								<span class="commentauthor">
										<a href="http://postneo.com/" rel="external nofollow">Matt Croydon</a>
								</span>
								<small class="commentmetadata">
										<a title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-7138">Aug 17th, 2005 at 5:37 pm</a>
								</small>
								<div class="itemtext">
										<p>Steve,</p>
										<p>Yeah, that would rock. I didn’t realize how much code I was going to have to escape and format before this post was done! </p>
								</div>
						</li>
						<li class="item" id="comment-7139">
								<a class="counter" title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-7139">5</a>
								<span class="commentauthor">Eugene Lazutkin</span>
								<small class="commentmetadata">
										<a title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-7139">Aug 17th, 2005 at 6:06 pm</a>
								</small>
								<div class="itemtext">
										<p>This is some cool stuff! It would be nice to have it as part of official Django documentation, if some small typos are corrected.</p>
										<p>Unfortunately this example doesn’t work out of box.</p>
										<p>1) Getting Started — make sure to create your database _before_ you run django-admin.py init. It is not going to be created for you. Official Tutorial 1 (which is mentioned after “init”) explains it in details.</p>
										<p>2) The Model — before going to play with the model make sure to install it using django-admin.py install tasks. It is explained in Official Tutorial 1.</p>
										<p>3) URL Configuration — probably urls should be decoupled as in Official Tutorial 3. It is better for novices to provide ready-made code instead of reference to Official Tutorial 3.</p>
										<p>4) URL Configuration — update should have the same parameters as create. Otherwise it doesn’t know where to forward to after updating.</p>
										<p>5) URL Configuration — most probably delete should forward to ‘/tasks/’. ‘/tasks/new/’ is not defined in your tutorial.</p>
										<p>6) Index — the same list is passed as ‘notdone_tasks_list’ and ‘done_tasks_list’. The latter should be done_task_list.</p>
										<p>7) Index — it should be noted that all template files are to be created in subdirectory ‘templates/tasks/’, not directly in ‘templates/’.</p>
										<p>8) Create Generic View — by some reasons tasks_form template has all ‘”‘ prepended with ‘\\’. They should be removed, otherwise it doesn’t work.</p>
										<p>9) Delete — tasks_form_delete template should be renamed to tasks_confirm_delete.</p>
										<p>I’m pretty sure that these tiny bugs are due to ongoing changes in Django and naturally occurring typos. Thank you for great tutorial! </p>
								</div>
						</li>
						<li class="authorcomment item" id="comment-7140">
								<a class="counter" title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-7140">6</a>
								<span class="commentauthor">
										<a href="http://postneo.com/" rel="external nofollow">Matt Croydon</a>
								</span>
								<small class="commentmetadata">
										<a title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-7140">Aug 17th, 2005 at 6:17 pm</a>
								</small>
								<div class="itemtext">
										<p>Eugene,</p>
										<p>Hey thanks for the feedback, I’ll do my best to update the tutorial this weekend. I did my best to get from scratch to my working situation, but I sure missed a couple of things along the way.</p>
										<p>Thanks again for taking the time to go throught the tutorial and pointing out the little things.</p>
										<p>Be aware that there are some significant and backwards-incompatible syntax changes for the models that might be showing up shortly, but I’ll definitely update this tutorial when/if that happens. </p>
								</div>
						</li>
						<li class="item" id="comment-7144">
								<a class="counter" title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-7144">7</a>
								<span class="commentauthor">Joseph Grace</span>
								<small class="commentmetadata">
										<a title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-7144">Aug 17th, 2005 at 8:19 pm</a>
								</small>
								<div class="itemtext">
										<p>Great article.</p>
										<p>Few minor additions that will help others (newb-&gt;newb). (I’m running django revision 525, FYI.)</p>
										<p>1. A little reminder to “django-admin.py init tasks” to create the database table in the initialized database would help just before the screen pic of the index.html.</p>
										<p>2. (r’^tasks/delete/(?P\d+)/?$’, […] post_delete_redirect=”/tasks/new/”) ),</p>
										<p>seems to work as</p>
										<p>(r’^tasks/delete/(?P\d+)/?$’, […] post_delete_redirect=”/tasks/create/”) ),</p>
										<p>instead.</p>
										<p>3. tasks_form_delete.html template seems to work as tasks_confirm_delete.hmtl instead</p>
										<p>-=-</p>
										<p>Awesome bite-sized article. Thanks for sharing. </p>
								</div>
						</li>
						<li class="item" id="comment-7172">
								<a class="counter" title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-7172">8</a>
								<span class="commentauthor">
										<a href="http://www.lazutkin.com/" rel="external nofollow">Eugene Lazutkin</a>
								</span>
								<small class="commentmetadata">
										<a title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-7172">Aug 18th, 2005 at 12:32 pm</a>
								</small>
								<div class="itemtext">
										<p>I forgot to mention django-admin.py createsuperuser. </p>
								</div>
						</li>
						<li class="item" id="comment-7233">
								<a class="counter" title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-7233">9</a>
								<span class="commentauthor">Lada</span>
								<small class="commentmetadata">
										<a title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-7233">Aug 20th, 2005 at 6:39 am</a>
								</small>
								<div class="itemtext">
										<p>Matt, thank you the tutorial. I tried it but stopped with<br />/tasks/create/<br />because in my MS Explorer there is no submit button shown. Only input field.<br />Is it a problem on my side( django installation or MS Explorer or similar)?<br />Thank you for your reply </p>
								</div>
						</li>
						<li class="item" id="comment-7234">
								<a class="counter" title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-7234">10</a>
								<span class="commentauthor">aCC</span>
								<small class="commentmetadata">
										<a title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-7234">Aug 20th, 2005 at 2:04 pm</a>
								</small>
								<div class="itemtext">
										<p>@Lada</p>
										<p>You need to edit the template “tasks_form.html” and change all \” to “ </p>
								</div>
						</li>
						<li class="item" id="comment-7345">
								<a class="counter" title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-7345">11</a>
								<span class="commentauthor">Lada</span>
								<small class="commentmetadata">
										<a title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-7345">Sep 3rd, 2005 at 4:02 am</a>
								</small>
								<div class="itemtext">
										<p>First of all , thank you Matt for the tutorial. I learnt a lot.</p>
										<p>But I think that UPDATE should also have post_save_redirect like Create Generic View. For me it did not work without that.<br />Best regards,<br />Lad. </p>
								</div>
						</li>
						<li class="item" id="comment-10038">
								<a class="counter" title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-10038">12</a>
								<span class="commentauthor">required</span>
								<small class="commentmetadata">
										<a title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-10038">Jan 17th, 2006 at 9:45 pm</a>
								</small>
								<div class="itemtext">
										<p>W A R N I N G ! ! ! :: This Tutorial is VERY MUCH OUT OF DATE!!! </p>
								</div>
						</li>
						<li class="item" id="comment-10341">
								<a class="counter" title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-10341">13</a>
								<span class="commentauthor">coulix</span>
								<small class="commentmetadata">
										<a title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-10341">Feb 3rd, 2006 at 4:57 am</a>
								</small>
								<div class="itemtext">
										<p>So what is out of day ? can we have an updated tutorial ? </p>
								</div>
						</li>
						<li class="item" id="comment-10869">
								<a class="counter" title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-10869">14</a>
								<span class="commentauthor">
										<a href="http://www.ijonas.com/" rel="external nofollow">Ijonas Kisselbach</a>
								</span>
								<small class="commentmetadata">
										<a title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-10869">Feb 22nd, 2006 at 5:42 pm</a>
								</small>
								<div class="itemtext">
										<p>This article may be slightly out-of-date, but it had far more useful examples on generic views to extrapolate from then the “official documentation” on the topic.</p>
										<p>Matt, many thanks! </p>
								</div>
						</li>
						<li class="item" id="comment-12389">
								<a class="counter" title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-12389">15</a>
								<span class="commentauthor">
										<a href="http://www.cookware-and-baking.info/" rel="external nofollow">Lev</a>
								</span>
								<small class="commentmetadata">
										<a title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-12389">Apr 12th, 2006 at 11:19 am</a>
								</small>
								<div class="itemtext">
										<p>hi<br />Prompt how to get rid of advertising? </p>
								</div>
						</li>
						<li class="item" id="comment-13130">
								<a class="counter" title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-13130">16</a>
								<span class="commentauthor">
										<a href="http://www.gay-butts.be/" rel="external nofollow">Lyndon</a>
								</span>
								<small class="commentmetadata">
										<a title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-13130">Apr 26th, 2006 at 5:03 am</a>
								</small>
								<div class="itemtext">
										<p>Cool gay butts are online now. Gay Butts shows its <a href="http://www.gay-butts.be/" rel="nofollow"></a><a href="http://www.gay-butts.be/" rel="nofollow">http://www.gay-butts.be</a> butts collection just in Febrary! </p>
								</div>
						</li>
						<li class="item" id="comment-46472">
								<a class="counter" title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-46472">17</a>
								<span class="commentauthor">
										<a href="http://www.analmovies-xxx.info/areblack.html" rel="external nofollow">Owen</a>
								</span>
								<small class="commentmetadata">
										<a title="Permanent Link to this Comment" href="http://www.postneo.com/2005/08/17/django-generic-views-crud#comment-46472">Nov 1st, 2006 at 6:30 am</a>
								</small>
								<div class="itemtext">
										<p>
												<a href="http://www.analmovies-xxx.info/gaycockhuge.html" rel="nofollow">gay cock huge</a>Watch these horny sluts taking it in the ass for the first time and getting their virgin butts ripped wide open.<br /><a href="http://www.analmovies-xxx.info/hotblonde.html" rel="nofollow">hot blonde huge dildo</a>It’s an experience they will never forget. Frenzied 3some and wild anal actions caught on video are waiting here for you. </p>
								</div>
						</li>
				</ol>
		</div>
<img src ="http://www.blogjava.net/pts/aggbug/86476.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pts/" target="_blank">pts</a> 2006-12-08 23:45 <a href="http://www.blogjava.net/pts/archive/2006/12/08/86476.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Django DOC of Generic views</title><link>http://www.blogjava.net/pts/archive/2006/12/08/86473.html</link><dc:creator>pts</dc:creator><author>pts</author><pubDate>Fri, 08 Dec 2006 15:31:00 GMT</pubDate><guid>http://www.blogjava.net/pts/archive/2006/12/08/86473.html</guid><wfw:comment>http://www.blogjava.net/pts/comments/86473.html</wfw:comment><comments>http://www.blogjava.net/pts/archive/2006/12/08/86473.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/pts/comments/commentRss/86473.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pts/services/trackbacks/86473.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 下面的是Django 官方的指南，不过http://www.postneo.com/2005/08/17/django-generic-views-crud上面讲解的也许更容易理解。 Generic views This covers Django version 0.95 and the development version. Old docs: 0.90, 0.91 Writing Web ...&nbsp;&nbsp;<a href='http://www.blogjava.net/pts/archive/2006/12/08/86473.html'>阅读全文</a><img src ="http://www.blogjava.net/pts/aggbug/86473.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pts/" target="_blank">pts</a> 2006-12-08 23:31 <a href="http://www.blogjava.net/pts/archive/2006/12/08/86473.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Django DOC of Model reference</title><link>http://www.blogjava.net/pts/archive/2006/12/05/85696.html</link><dc:creator>pts</dc:creator><author>pts</author><pubDate>Tue, 05 Dec 2006 14:08:00 GMT</pubDate><guid>http://www.blogjava.net/pts/archive/2006/12/05/85696.html</guid><wfw:comment>http://www.blogjava.net/pts/comments/85696.html</wfw:comment><comments>http://www.blogjava.net/pts/archive/2006/12/05/85696.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/pts/comments/commentRss/85696.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pts/services/trackbacks/85696.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Model referenceThis covers Django version 0.95 and the development version. Old docs: 0.90, 0.91A model is the single, definitive source of data about your data. It contains the essential fields and...&nbsp;&nbsp;<a href='http://www.blogjava.net/pts/archive/2006/12/05/85696.html'>阅读全文</a><img src ="http://www.blogjava.net/pts/aggbug/85696.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pts/" target="_blank">pts</a> 2006-12-05 22:08 <a href="http://www.blogjava.net/pts/archive/2006/12/05/85696.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Django DOC of django-admin.py and manage.py</title><link>http://www.blogjava.net/pts/archive/2006/12/05/85660.html</link><dc:creator>pts</dc:creator><author>pts</author><pubDate>Tue, 05 Dec 2006 11:45:00 GMT</pubDate><guid>http://www.blogjava.net/pts/archive/2006/12/05/85660.html</guid><wfw:comment>http://www.blogjava.net/pts/comments/85660.html</wfw:comment><comments>http://www.blogjava.net/pts/archive/2006/12/05/85660.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/pts/comments/commentRss/85660.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pts/services/trackbacks/85660.html</trackback:ping><description><![CDATA[
<div class="document" id="django-admin-py-and-manage-py">
<h1 class="title">django-admin.py and manage.py</h1>
<h2 class="deck">This covers Django version 0.95 and the development version. Old docs: <a href="http://www.djangoproject.com/documentation/0_90/"><span style="COLOR: #ab5603">0.90</span></a>, <a href="http://www.djangoproject.com/documentation/0_91/"><span style="COLOR: #ab5603">0.91</span></a></h2>
<p><tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">django-admin.py</span></span></tt> is Django's command-line utility for administrative tasks. This document outlines all it can do.</p>
<p>django-admin.py是Django的命令行管理系统，这篇文档将详细介绍他的功能。</p>
<p>In addition, <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">manage.py</span></span></tt> is automatically created in each Django project. <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">manage.py</span></span></tt> is a thin wrapper around <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">django-admin.py</span></span></tt> that takes care of two things for you before delegating to <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">django-admin.py</span></span></tt>:<br/>实际上，文件manage.py会在每个Django工程创立的时候自动建立，manage.py是django-admin.py功能的一个简单封装，它会为django-admin.py启用之前做好两项工作：</p>
<blockquote>
<ul class="simple">
<li>It puts your project's package on <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">sys.path</span></span></tt>.</li>
<li>将工程包文件放入sys.path路径</li>
<li>It sets the <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">DJANGO_SETTINGS_MODULE</span></span></tt> environment variable so that it points to your project's <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">settings.py</span></span></tt> file.</li>
<li>设置DJANGO_SETTINGS_MODULE变量指向你创立工程中的settings.py文件。</li>
</ul>
</blockquote>
<p>The <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">django-admin.py</span></span></tt> script should be on your system path if you installed Django via its <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">setup.py</span></span></tt> utility. If it's not on your path, you can find it in <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">site-packages/django/bin</span></span></tt> within your Python installation. Consider symlinking to it from some place on your path, such as <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">/usr/local/bin</span></span></tt>.<br/>如果你通过setup.py方式安装Django，django-admin.py脚本会被加入到系统路径。如果不在系统路径，你可以在Python安装路径下的site-packages/django/bin目录下找到，并将他加入到你的系统路径下。</p>
<p>Generally, when working on a single Django project, it's easier to use <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">manage.py</span></span></tt>. Use <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">django-admin.py</span></span></tt> with <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">DJANGO_SETTINGS_MODULE</span></span></tt>, or the <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">--settings</span></span></tt> command line option, if you need to switch between multiple Django settings files.<br/>一般情况下，对单个Django project，使用manage.py没有什么问题，如果你需要在不同的Django project间使用django-admin.py，那么需要使用DJANGO_SETTINGS_MODULE或--settings命令行参数。</p>
<div class="section" id="usage">
<h2>Usage</h2>
<p><tt class="docutils literal"><span style="COLOR: #234f32"><span class="pre">django-admin.py</span> <span class="pre">action</span> <span class="pre">[options]</span></span></tt></p>
<p><tt class="docutils literal"><span style="COLOR: #234f32"><span class="pre">manage.py</span> <span class="pre">action</span> <span class="pre">[options]</span></span></tt></p>
<p><tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">action</span></span></tt> should be one of the actions listed in this document. <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">options</span></span></tt>, which is optional, should be zero or more of the options listed in this document.</p>
<p>Run <tt class="docutils literal"><span style="COLOR: #234f32"><span class="pre">django-admin.py</span> <span class="pre">--help</span></span></tt> to display a help message that includes a terse list of all available actions and options.</p>
<p>Most actions take a list of <tt class="docutils literal"><span style="COLOR: #234f32"><span class="pre">appname``s.</span> <span class="pre">An</span> <span class="pre">``appname</span></span></tt> is the basename of the package containing your models. For example, if your <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">INSTALLED_APPS</span></span></tt> contains the string <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">'mysite.blog'</span></span></tt>, the <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">appname</span></span></tt> is <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">blog</span></span></tt>.</p>
</div>
<div class="section" id="available-actions">
<h2>Available actions</h2>
<div class="section" id="adminindex-appname-appname">
<h3>adminindex [appname appname ...]</h3>
<p>Prints the admin-index template snippet for the given appnames.</p>
<p>Use admin-index template snippets if you want to customize the look and feel of your admin's index page. See <a href="http://www.djangoproject.com/documentation/tutorial2/" class="reference"><span style="COLOR: #ab5603">Tutorial 2</span></a> for more information.</p>
</div>
<div class="section" id="createcachetable-tablename">
<h3>createcachetable [tablename]</h3>
<p>Creates a cache table named <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">tablename</span></span></tt> for use with the database cache backend. See the <a href="http://www.djangoproject.com/documentation/cache/" class="reference"><span style="COLOR: #ab5603">cache documentation</span></a> for more information.</p>
</div>
<div class="section" id="dbshell">
<h3>dbshell</h3>
<p>Runs the command-line client for the database engine specified in your <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">DATABASE_ENGINE</span></span></tt> setting, with the connection parameters specified in your <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">DATABASE_USER</span></span></tt>, <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">DATABASE_PASSWORD</span></span></tt>, etc., settings.</p>
<blockquote>
<ul class="simple">
<li>For PostgreSQL, this runs the <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">psql</span></span></tt> command-line client.</li>
<li>For MySQL, this runs the <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">mysql</span></span></tt> command-line client.</li>
<li>For SQLite, this runs the <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">sqlite3</span></span></tt> command-line client.</li>
</ul>
</blockquote>
<p>This command assumes the programs are on your <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">PATH</span></span></tt> so that a simple call to the program name (<tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">psql</span></span></tt>, <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">mysql</span></span></tt>, <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">sqlite3</span></span></tt>) will find the program in the right place. There's no way to specify the location of the program manually.</p>
</div>
<div class="section" id="diffsettings">
<h3>diffsettings</h3>
<p>Displays differences between the current settings file and Django's default settings.<br/>比较当前settings文件和Django缺省settings文件之间的差异。</p>
<p>Settings that don't appear in the defaults are followed by <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">"###"</span></span></tt>. For example, the default settings don't define <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">ROOT_URLCONF</span></span></tt>, so <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">ROOT_URLCONF</span></span></tt> is followed by <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">"###"</span></span></tt> in the output of <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">diffsettings</span></span></tt>.<br/>在缺省settings中不存在的以"###"标识。</p>
<p>Note that Django's default settings live in <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">django/conf/global_settings.py</span></span></tt>, if you're ever curious to see the full list of defaults.</p>
</div>
<div class="section" id="inspectdb">
<h3><span style="TEXT-DECORATION: underline">inspectdb</span></h3>
<p>Introspects the database tables in the database pointed-to by the <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">DATABASE_NAME</span></span></tt> setting and outputs a Django model module (a <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">models.py</span></span></tt> file) to standard output.</p>
<p>Use this if you have a legacy database with which you'd like to use Django. The script will inspect the database and create a model for each table within it.</p>
<p>As you might expect, the created models will have an attribute for every field in the table. Note that <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">inspectdb</span></span></tt> has a few special cases in its field-name output:</p>
<blockquote>
<ul class="simple">
<li>If <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">inspectdb</span></span></tt> cannot map a column's type to a model field type, it'll use <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">TextField</span></span></tt> and will insert the Python comment <tt class="docutils literal"><span style="COLOR: #234f32"><span class="pre">'This</span> <span class="pre">field</span> <span class="pre">type</span> <span class="pre">is</span> <span class="pre">a</span> <span class="pre">guess.'</span></span></tt> next to the field in the generated model.</li>
<li>If the database column name is a Python reserved word (such as <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">'pass'</span></span></tt>, <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">'class'</span></span></tt> or <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">'for'</span></span></tt>), <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">inspectdb</span></span></tt> will append <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">'_field'</span></span></tt> to the attribute name. For example, if a table has a column <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">'for'</span></span></tt>, the generated model will have a field <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">'for_field'</span></span></tt>, with the <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">db_column</span></span></tt> attribute set to <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">'for'</span></span></tt>. <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">inspectdb</span></span></tt> will insert the Python comment <tt class="docutils literal"><span style="COLOR: #234f32"><span class="pre">'Field</span> <span class="pre">renamed</span> <span class="pre">because</span> <span class="pre">it</span> <span class="pre">was</span> <span class="pre">a</span> <span class="pre">Python</span> <span class="pre">reserved</span> <span class="pre">word.'</span></span></tt> next to the field.</li>
</ul>
</blockquote>
<p>This feature is meant as a shortcut, not as definitive model generation. After you run it, you'll want to look over the generated models yourself to make customizations. In particular, you'll need to rearrange models' order, so that models that refer to other models are ordered properly.</p>
<p>Primary keys are automatically introspected for PostgreSQL, MySQL and SQLite, in which case Django puts in the <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">primary_key=True</span></span></tt> where needed.</p>
<p><tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">inspectdb</span></span></tt> works with PostgreSQL, MySQL and SQLite. Foreign-key detection only works in PostgreSQL and with certain types of MySQL tables.</p>
</div>
<div class="section" id="install-appname-appname">
<h3>install [appname appname ...]</h3>
<p>Executes the equivalent of <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">sqlall</span></span></tt> for the given appnames.</p>
</div>
<div class="section" id="runserver-optional-port-number-or-ipaddr-port">
<h3>runserver [optional port number, or ipaddr:port]</h3>
<p>Starts a lightweight development Web server on the local machine. By default, the server runs on port 8000 on the IP address 127.0.0.1. You can pass in an IP address and port number explicitly.</p>
<p>If you run this script as a user with normal privileges (recommended), you might not have access to start a port on a low port number. Low port numbers are reserved for the superuser (root).</p>
<p>DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through security audits or performance tests. (And that's how it's gonna stay. We're in the business of making Web frameworks, not Web servers, so improving this server to be able to handle a production environment is outside the scope of Django.)</p>
<p>The development server automatically reloads Python code for each request, as needed. You don't need to restart the server for code changes to take effect.</p>
<p>When you start the server, and each time you change Python code while the server is running, the server will validate all of your installed models. (See the <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">validate</span></span></tt> command below.) If the validator finds errors, it will print them to standard output, but it won't stop the server.</p>
<p>You can run as many servers as you want, as long as they're on separate ports. Just execute <tt class="docutils literal"><span style="COLOR: #234f32"><span class="pre">django-admin.py</span> <span class="pre">runserver</span></span></tt> more than once.</p>
<p>Note that the default IP address, 127.0.0.1, is not accessible from other machines on your network. To make your development server viewable to other machines on the network, use its own IP address (e.g. <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">192.168.2.1</span></span></tt>) or <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">0.0.0.0</span></span></tt>.</p>
<div class="section" id="examples">
<h4>Examples:</h4>
<p>Port 7000 on IP address 127.0.0.1:</p>
<pre xml:space="preserve" class="literal-block">
django-admin.py runserver 7000
</pre>
<p>Port 7000 on IP address 1.2.3.4:</p>
<pre xml:space="preserve" class="literal-block">
django-admin.py runserver 1.2.3.4:7000
</pre></div>
<div class="section" id="serving-static-files-with-the-development-server">
<h4>Serving static files with the development server</h4>
<p>By default, the development server doesn't serve any static files for your site (such as CSS files, images, things under <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">MEDIA_ROOT_URL</span></span></tt> and so forth). If you want to configure Django to serve static media, read the <a href="http://www.djangoproject.com/documentation/static_files/" class="reference"><span style="COLOR: #ab5603">serving static files</span></a> documentation.</p>
</div>
<div class="section" id="turning-off-auto-reload">
<h4>Turning off auto-reload</h4>
<p>To disable auto-reloading of code while the development server is running, use the <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">--noreload</span></span></tt> option, like so:<br/>如果要在服务已启动后禁止自动加载代码功能，可使用--noreload参数。</p>
<pre xml:space="preserve" class="literal-block">
django-admin.py runserver --noreload
</pre></div>
</div>
<div class="section" id="shell">
<h3>shell</h3>
<p>Starts the Python interactive interpreter.</p>
<p>Django will use <a href="http://ipython.scipy.org/" class="reference"><span style="COLOR: #ab5603">IPython</span></a>, if it's installed. <span style="TEXT-DECORATION: underline">If you have IPython installed and want to force use of the "plain" Python interpreter, use the <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">--plain</span></span></tt> option, like so:</span></p>
<p>django-admin.py shell --plain</p>
<p><strong>sql [appname appname ...]</strong></p>
</div>
<div class="section" id="sql-appname-appname">
<p>Prints the CREATE TABLE SQL statements for the given appnames.</p>
</div>
<div class="section" id="sqlall-appname-appname">
<h3>sqlall [appname appname ...]</h3>
<p>Prints the CREATE TABLE and initial-data SQL statements for the given appnames.</p>
<p>Refer to the description of <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">sqlinitialdata</span></span></tt> for an explanation of how to specify initial data.</p>
</div>
<div class="section" id="sqlclear-appname-appname">
<h3>sqlclear [appname appname ...]</h3>
<p>Prints the DROP TABLE SQL statements for the given appnames.</p>
</div>
<div class="section" id="sqlindexes-appname-appname">
<h3>sqlindexes [appname appname ...]</h3>
<p>Prints the CREATE INDEX SQL statements for the given appnames.</p>
</div>
<div class="section" id="sqlinitialdata-appname-appname">
<h3>sqlinitialdata [appname appname ...]</h3>
<p>Prints the initial INSERT SQL statements for the given appnames.</p>
<p>For each model in each specified app, this command looks for the file <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">&lt;appname&gt;/sql/&lt;modelname&gt;.sql</span></span></tt>, where <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">&lt;appname&gt;</span></span></tt> is the given appname and <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">&lt;modelname&gt;</span></span></tt> is the model's name in lowercase. For example, if you have an app <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">news</span></span></tt> that includes a <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">Story</span></span></tt> model, <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">sqlinitialdata</span></span></tt> will attempt to read a file <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">news/sql/story.sql</span></span></tt> and append it to the output of this command.</p>
<p>Each of the SQL files, if given, is expected to contain valid SQL. The SQL files are piped directly into the database after all of the models' table-creation statements have been executed. Use this SQL hook to populate tables with any necessary initial records, SQL functions or test data.</p>
</div>
<div class="section" id="sqlreset-appname-appname">
<h3><span style="TEXT-DECORATION: underline">sqlreset [appname appname ...]</span></h3>
<p>Prints the DROP TABLE SQL, then the CREATE TABLE SQL, for the given appnames.</p>
</div>
<div class="section" id="sqlsequencereset-appname-appname">
<h3>sqlsequencereset [appname appname ...]</h3>
<p>Prints the SQL statements for resetting PostgreSQL sequences for the given appnames.</p>
<p>See <a href="http://simon.incutio.com/archive/2004/04/21/postgres" class="reference"><span style="COLOR: #ab5603">http://simon.incutio.com/archive/2004/04/21/postgres</span></a> for more information.</p>
</div>
<div class="section" id="startapp-appname">
<h3>startapp [appname]</h3>
<p>Creates a Django app directory structure for the given app name in the current directory.</p>
</div>
<div class="section" id="startproject-projectname">
<h3>startproject [projectname]</h3>
<p>Creates a Django project directory structure for the given project name in the current directory.</p>
</div>
<div class="section" id="syncdb">
<h3>syncdb</h3>
<p>Creates the database tables for all apps in <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">INSTALLED_APPS</span></span></tt> whose tables have not already been created.</p>
<p>Use this command when you've added new applications to your project and want to install them in the database. This includes any apps shipped with Django that might be in <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">INSTALLED_APPS</span></span></tt> by default. When you start a new project, run this command to install the default apps.</p>
<p>If you're installing the <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">django.contrib.auth</span></span></tt> application, <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">syncdb</span></span></tt> will give you the option of creating a superuser immediately.</p>
</div>
<div class="section" id="test">
<h3>test</h3>
<p><strong>New in Django development version</strong></p>
<p>Discover and run tests for all installed models. See <a href="http://www.djangoproject.com/documentation/testing/" class="reference"><span style="COLOR: #ab5603">Testing Django applications</span></a> for more information.</p>
</div>
<div class="section" id="validate">
<h3>validate</h3>
<p>Validates all installed models (according to the <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">INSTALLED_APPS</span></span></tt> setting) and prints validation errors to standard output.</p>
</div>
</div>
<div class="section" id="available-options">
<h2>Available options</h2>
<div class="section" id="settings">
<h3>--settings</h3>
<p>Example usage:</p>
<pre xml:space="preserve" class="literal-block">
django-admin.py syncdb --settings=mysite.settings
</pre>
<p>Explicitly specifies the settings module to use. The settings module should be in Python package syntax, e.g. <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">mysite.settings</span></span></tt>. If this isn't provided, <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">django-admin.py</span></span></tt> will use the <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">DJANGO_SETTINGS_MODULE</span></span></tt> environment variable.</p>
<p>Note that this option is unnecessary in <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">manage.py</span></span></tt>, because it takes care of setting <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">DJANGO_SETTINGS_MODULE</span></span></tt> for you.</p>
</div>
<div class="section" id="pythonpath">
<h3>--pythonpath</h3>
<p>Example usage:</p>
<pre xml:space="preserve" class="literal-block">
django-admin.py syncdb --pythonpath='/home/djangoprojects/myproject'
</pre>
<p>Adds the given filesystem path to the Python <a href="http://diveintopython.org/getting_to_know_python/everything_is_an_object.html" class="reference"><span style="COLOR: #ab5603">import search path</span></a>. If this isn't provided, <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">django-admin.py</span></span></tt> will use the <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">PYTHONPATH</span></span></tt> environment variable.</p>
<p>Note that this option is unnecessary in <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">manage.py</span></span></tt>, because it takes care of setting the Python path for you.</p>
</div>
<div class="section" id="help">
<h3>--help</h3>
<p>Displays a help message that includes a terse list of all available actions and options.</p>
</div>
<div class="section" id="noinput">
<h3>--noinput</h3>
<p><strong>New in Django development version</strong></p>
<p>Inform django-admin that the user should NOT be prompted for any input. Useful if the django-admin script will be executed as an unattended, automated script.</p>
</div>
<div class="section" id="noreload">
<h3>--noreload</h3>
<p>Disable the use of the auto-reloader when running the development server.</p>
</div>
<div class="section" id="version">
<h3>--version</h3>
<p>Displays the current Django version.</p>
<p>Example output:</p>
<pre xml:space="preserve" class="literal-block">
0.9.1
0.9.1 (SVN)
</pre></div>
<div class="section" id="verbosity">
<h3>--verbosity</h3>
<p><strong>New in Django development version</strong></p>
<p>Example usage:</p>
<pre xml:space="preserve" class="literal-block">
django-admin.py syncdb --verbosity=2
</pre>
<p>Verbosity determines the amount of notification and debug information that will be printed to the console. '0' is no output, '1' is normal output, and <cite>2</cite> is verbose output.<br/>verbosity决定运行、调试信息显示级别，0－什么也不输出，1－正常输出，2－详细信息输出</p>
</div>
<div class="section" id="adminmedia">
<h3>--adminmedia</h3>
<p><strong>New in Django development version</strong></p>
<dl class="docutils">
<dt>Example usage::</dt>
<dd>django-admin.py manage.py --adminmedia=/tmp/new-admin-style/</dd>
</dl>
<p>Tells Django where to find the various CSS and JavaScript files for the admin interface when running the development server. Normally these files are served out of the Django source tree, but because some designers customize these files for their site, this option allows you to test against custom versions.</p>
</div>
</div>
<div class="section" id="extra-niceties">
<h2>Extra niceties</h2>
<div class="section" id="syntax-coloring">
<h3>Syntax coloring</h3>
<p>The <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">django-admin.py</span></span></tt> / <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">manage.py</span></span></tt> commands that output SQL to standard output will use pretty color-coded output if your terminal supports ANSI-colored output. It won't use the color codes if you're piping the command's output to another program.</p>
</div>
<div class="section" id="bash-completion">
<h3>Bash completion</h3>
<p>If you use the Bash shell, consider installing the Django bash completion script, which lives in <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">extras/django_bash_completion</span></span></tt> in the Django distribution. It enables tab-completion of <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">django-admin.py</span></span></tt> and <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">manage.py</span></span></tt> commands, so you can, for instance...</p>
<blockquote>
<ul class="simple">
<li>Type <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">django-admin.py</span></span></tt>.</li>
<li>Press [TAB] to see all available options.</li>
<li>Type <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">sql</span></span></tt>, then [TAB], to see all available options whose names start with <tt class="docutils literal"><span class="pre"><span style="COLOR: #234f32">sql</span></span></tt>.</li>
</ul>
</blockquote>
</div>
</div>
</div>
<br/><h2 id="comments">Comments</h2>
<div class="comment" id="c2315">
<h3>Indy <span class="small quiet"><span style="FONT-SIZE: 0.75em; COLOR: #90ba9e">September 27, 2006 at 4:04 a.m.</span></span></h3>
<p>A small addition:<br/>"Note that the default IP address, 127.0.0.1, is not accessible from other machines on your network. To make your development server viewable to other machines on the network, use its own IP address (e.g. 192.168.2.1) or 0.0.0.0." ... _as start parameter (e.g. manage.py runserver 192.168.2.1:8000)_</p>
</div>
<br/><p class="poweredbyzoundry">Powered by <a href="http://www.zoundry.com" class="poweredbyzoundry_link" rel="nofollow">Zoundry</a></p>
<img src ="http://www.blogjava.net/pts/aggbug/85660.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pts/" target="_blank">pts</a> 2006-12-05 19:45 <a href="http://www.blogjava.net/pts/archive/2006/12/05/85660.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>The Django template language: For Python programmers</title><link>http://www.blogjava.net/pts/archive/2006/12/05/85656.html</link><dc:creator>pts</dc:creator><author>pts</author><pubDate>Tue, 05 Dec 2006 11:25:00 GMT</pubDate><guid>http://www.blogjava.net/pts/archive/2006/12/05/85656.html</guid><wfw:comment>http://www.blogjava.net/pts/comments/85656.html</wfw:comment><comments>http://www.blogjava.net/pts/archive/2006/12/05/85656.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/pts/comments/commentRss/85656.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pts/services/trackbacks/85656.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: The Django template language: For Python programmersThis covers Django version 0.95 and the development version. Old docs: 0.90, 0.91This document explains the Django template system from a technica...&nbsp;&nbsp;<a href='http://www.blogjava.net/pts/archive/2006/12/05/85656.html'>阅读全文</a><img src ="http://www.blogjava.net/pts/aggbug/85656.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pts/" target="_blank">pts</a> 2006-12-05 19:25 <a href="http://www.blogjava.net/pts/archive/2006/12/05/85656.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>The Django template language: For template authors</title><link>http://www.blogjava.net/pts/archive/2006/11/30/84666.html</link><dc:creator>pts</dc:creator><author>pts</author><pubDate>Thu, 30 Nov 2006 14:15:00 GMT</pubDate><guid>http://www.blogjava.net/pts/archive/2006/11/30/84666.html</guid><wfw:comment>http://www.blogjava.net/pts/comments/84666.html</wfw:comment><comments>http://www.blogjava.net/pts/archive/2006/11/30/84666.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/pts/comments/commentRss/84666.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pts/services/trackbacks/84666.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: The Django template language: For template authorsThis covers Django version 0.95 and the development version. Old docs: 0.90, 0.91Django's template language is designed to strike a balance between ...&nbsp;&nbsp;<a href='http://www.blogjava.net/pts/archive/2006/11/30/84666.html'>阅读全文</a><img src ="http://www.blogjava.net/pts/aggbug/84666.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pts/" target="_blank">pts</a> 2006-11-30 22:15 <a href="http://www.blogjava.net/pts/archive/2006/11/30/84666.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Django 问题</title><link>http://www.blogjava.net/pts/archive/2006/11/28/84159.html</link><dc:creator>pts</dc:creator><author>pts</author><pubDate>Tue, 28 Nov 2006 14:47:00 GMT</pubDate><guid>http://www.blogjava.net/pts/archive/2006/11/28/84159.html</guid><wfw:comment>http://www.blogjava.net/pts/comments/84159.html</wfw:comment><comments>http://www.blogjava.net/pts/archive/2006/11/28/84159.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/pts/comments/commentRss/84159.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pts/services/trackbacks/84159.html</trackback:ping><description><![CDATA[[有待深入了解]<br />1、模板<br />Django的模板确实很是灵活，但也有不少限制和不足，感觉不爽，主要是标签太少；不能直接使用python代码。<br /><br />难道必须使用自定义的模板语言？<br /><img src ="http://www.blogjava.net/pts/aggbug/84159.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pts/" target="_blank">pts</a> 2006-11-28 22:47 <a href="http://www.blogjava.net/pts/archive/2006/11/28/84159.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>DjangoBook note</title><link>http://www.blogjava.net/pts/archive/2006/11/28/84133.html</link><dc:creator>pts</dc:creator><author>pts</author><pubDate>Tue, 28 Nov 2006 12:27:00 GMT</pubDate><guid>http://www.blogjava.net/pts/archive/2006/11/28/84133.html</guid><wfw:comment>http://www.blogjava.net/pts/comments/84133.html</wfw:comment><comments>http://www.blogjava.net/pts/archive/2006/11/28/84133.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/pts/comments/commentRss/84133.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pts/services/trackbacks/84133.html</trackback:ping><description><![CDATA[
		<p>DjangoBook note <br />模板 <br />1、用 html 文件保存，设计的变量用 {{value_name}} 填充 <br />2、需 from django.template import Template,Context 导入库 <br />3、t=Template( 模板文件名 ) <br /> c=Context( 模板变量内容 ) <br /> t.render(c)# 可以输出模板内容 <br />4、   下面这段不理解什么意思 <br /> To prevent this, set a function attribute alters_data on the method. The template system won ’ t execute a method if the method has alters_data=True set. For example: <br /> def delete(self): <br />  # Delete the account <br /> delete.alters_data = True <br />5、 Context 对象支持 push()/pop() 方法 <br />6、 模板文件中的标签： <br /> 没有 elseif; <br /> For 循环中没有 break 和 continue <br /> For 循环中的几个属性： <br />    forloop.counter     # 当前循环的次数，从 1 开始 <br />    forloop.counter0    # 当前循环的次数，从 0 开始 <br />    forloop.revcounter        # 当前循环剩余次数，从总循环次数递减 <br />    forloop.revcounter0       # 当前循环剩余次数，从总循环次数 -1 递减 <br />    forloop.first             #boolean 值，如果为第一次循环，值为真 <br />    forloop.last              # 同上 <br />    forloop.parentloop        # 引用父循环的 forloop 对象 <br /> ifequal A B  ＃ AB 只能是模板变量、字符串、数字 <br />    pass ＃如果 A B 相等则执行 <br /> else <br />    pass ＃否则执行 <br /> endifequal <br /> {#   #}      ＃注释 <br /> {{A|B:”s”}}         # 对 A 执行 B 过滤， B 过滤可以有参数 <br />   几个过滤器： <br />   addslashes    加反斜杠 <br />   Date          格式化日期为字符串 <br />   escape        转换为网页编码 <br />   length        长度 <br />7、 模板不能建立一个变量或者改变一个变量的值；不能调用原生的 python 代码 <br />8、 在 setting.py 中制定模板文件存放的目录（ EMPLATE_DIRS ），例： <br /> TEMPLATE_DIRS = ( <br />  '/home/django/mysite/templates', <br /> ) <br /> 不要忘了最后的逗号，除非你将序列（）换成列表 [] ，但效率会降低；目录用 / 间隔 <br />9、 使用模板： <br /> from django.shortcuts import render_to_response<br /> import datetime</p>
		<p> def current_datetime(request):<br />  now = datetime.datetime.now()<br /> return render_to_response('current_datetime.html', {'current_date': now})<br /> 可以将填充到模板的变量换为locals()，但性能会有所下降，如<br /> def current_datetime(request):<br />  current_date = datetime.datetime.now()<br />    return render_to_response('current_datetime.html', locals())<br />10、如果要引用设定的模板目录中子目录的模板文件 ; <br /> t = get_template('dateapp/current_datetime.html')<br />11、模板可嵌套，模板文件名可用变量 <br /> {% include 'includes/nav.html' %}<br /> {% include template_name %}<br />12、模板继承，使用 extends 和一个特殊的标签 block ，例： <br /> ＃base.html<br /> &lt;head&gt;<br /> &lt;title&gt; <br />  {% block title %}标题{% endblock %}<br /> &lt;/title&gt;<br /> &lt;/head&gt;<br /> &lt;body&gt; <br /> {% block content %}内容{% endblock %}<br /> {% block footer %} 页尾{% endblock %}<br /> &lt;/body&gt;<br /> &lt;/html&gt;<br />  下面的模板继承自 base.html <br /> {% extends "base.html" %}     ＃这一行必须是第一个模板标签行 <br /> {% block title %} 我的标题 {% endblock %} <br /> {% block content %} <br />  &lt;p&gt; 我的内容 &lt;/p&gt; <br /> {% endblock %}   ＃不一定要重新定义父模板中的每个模板块 <br /> 通过 block.super 引用父模板块内容 <br /></p>
<img src ="http://www.blogjava.net/pts/aggbug/84133.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pts/" target="_blank">pts</a> 2006-11-28 20:27 <a href="http://www.blogjava.net/pts/archive/2006/11/28/84133.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Django资源纪录</title><link>http://www.blogjava.net/pts/archive/2006/11/27/83921.html</link><dc:creator>pts</dc:creator><author>pts</author><pubDate>Mon, 27 Nov 2006 15:50:00 GMT</pubDate><guid>http://www.blogjava.net/pts/archive/2006/11/27/83921.html</guid><wfw:comment>http://www.blogjava.net/pts/comments/83921.html</wfw:comment><comments>http://www.blogjava.net/pts/archive/2006/11/27/83921.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/pts/comments/commentRss/83921.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pts/services/trackbacks/83921.html</trackback:ping><description><![CDATA[
		<p>
				<a href="http://www.djangobook.com/en/beta/">http://www.djangobook.com/en/beta/</a> 很不错的django在线教程。 </p>
		<p>
				<a href="http://groups.google.com/group/django-users">http://groups.google.com/group/django-users</a> django的google论坛列表 </p>
		<p>
				<a href="http://www.djangoproject.com/documentation/">http://www.djangoproject.com/documentation/</a> django官方文档 </p>
		<p>
				<a href="http://code.djangoproject.com/browser/django/trunk/docs">http://code.djangoproject.com/browser/django/trunk/docs</a> django官方最新文档 可下载</p>
<img src ="http://www.blogjava.net/pts/aggbug/83921.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pts/" target="_blank">pts</a> 2006-11-27 23:50 <a href="http://www.blogjava.net/pts/archive/2006/11/27/83921.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>温习python ，Starting ――django</title><link>http://www.blogjava.net/pts/archive/2006/11/24/83149.html</link><dc:creator>pts</dc:creator><author>pts</author><pubDate>Thu, 23 Nov 2006 16:21:00 GMT</pubDate><guid>http://www.blogjava.net/pts/archive/2006/11/24/83149.html</guid><wfw:comment>http://www.blogjava.net/pts/comments/83149.html</wfw:comment><comments>http://www.blogjava.net/pts/archive/2006/11/24/83149.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/pts/comments/commentRss/83149.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/pts/services/trackbacks/83149.html</trackback:ping><description><![CDATA[
		<p>突然对python又感兴趣了。 </p>
		<p>以前看过，重新温习，开始看python框架Django，已经安装，默认初始欢迎界面已经出现了，根据<a href="http://www.woodpecker.org.cn/obp/django/django-stepbystep/newtest/doc/#id3">http://www.woodpecker.org.cn/obp/django/django-stepbystep/newtest/doc/#id3</a>介绍内容学习，却出现了错误： </p>
		<p>Could not import newtest.helloworld. Error was: No module named httpwrappers </p>
		<p>查看django lib，确实没有这个类，查找原因ing…......<br /><br />[24日补充]<br />google到了原因：<br />HttpResponse类从django.utils.httpwrapers改到了django.http<br />参见：<br /><a href="http://python.cn/pipermail/python-chinese/2006-April/023980.html">http://python.cn/pipermail/python-chinese/2006-April/023980.html</a><br /><a href="http://code.djangoproject.com/wiki/NamespaceSimplification">http://code.djangoproject.com/wiki/NamespaceSimplification</a><br />[再补充]<br />自我感觉dj的缺点：单独的标签库，没有完全使用python；框架结构不是很清晰，不如tapestry；<br /></p>
<img src ="http://www.blogjava.net/pts/aggbug/83149.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/pts/" target="_blank">pts</a> 2006-11-24 00:21 <a href="http://www.blogjava.net/pts/archive/2006/11/24/83149.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>