<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>迷途知返 &#187; Python</title>
	<atom:link href="http://pwwang.com/category/technology/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://pwwang.com</link>
	<description>专注技术,用心生活!</description>
	<lastBuildDate>Fri, 11 Nov 2011 11:29:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Call global variables in PHP and Python</title>
		<link>http://pwwang.com/2011/03/14/call-global-variables-in-php-and-python/</link>
		<comments>http://pwwang.com/2011/03/14/call-global-variables-in-php-and-python/#comments</comments>
		<pubDate>Mon, 14 Mar 2011 03:14:57 +0000</pubDate>
		<dc:creator>pwwang</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://pwwang.com/?p=988</guid>
		<description><![CDATA[&#160;

Call global variables in PHP

we need to declare the variables with &#8216;global&#8217; statement.

<span class="readmore"><a href="http://pwwang.com/2011/03/14/call-global-variables-in-php-and-python/" title="Call global variables in PHP and Python">Read More: 398 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>Call global variables in PHP</p>
<p>we need to declare the variables with &#8216;global&#8217; statement.</p>
<p>&nbsp;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$var</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$var</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>&nbsp;</p>
<p>While in Python, it&#8217;s not necessary to declare the global variables when reading it</p>
<p>&nbsp;</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">var = <span style="color: #ff4500;">1</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> foo<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> var</pre></div></div>

<p>&nbsp;</p>
<p>However, if you&#8217;d like to change the variables, you need to declare it as same as in PHP</p>
<p>&nbsp;</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">var = <span style="color: #ff4500;">1</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> foo<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">global</span> var
    var = var + <span style="color: #ff4500;">1</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> var</pre></div></div>

<p>&nbsp;</p>
<p>Otherwise, an error like &quot;local variable &#8216;xxx&#8217; referenced before assignment&quot; will occur</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://pwwang.com/2011/03/14/call-global-variables-in-php-and-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PyChartDirector中文教程[8]：饼图的图例</title>
		<link>http://pwwang.com/2010/05/18/pychartdirector8/</link>
		<comments>http://pwwang.com/2010/05/18/pychartdirector8/#comments</comments>
		<pubDate>Tue, 18 May 2010 02:13:24 +0000</pubDate>
		<dc:creator>pwwang</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[ChartDirector]]></category>

		<guid isPermaLink="false">http://pwwang.com/?p=933</guid>
		<description><![CDATA[&#160;

上节我们说了标签，这节我们来说图例：

先看图

<span class="readmore"><a href="http://pwwang.com/2010/05/18/pychartdirector8/" title="PyChartDirector中文教程[8]：饼图的图例">Read More: 3789 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>上节我们说了标签，这节我们来说图例：</p>
<p>先看图</p>
<p><a href="http://pwwang.com/wp-content/uploads/2010/05/legendpie.png"><img width="300" height="180" border="0" title="legendpie" src="http://pwwang.com/wp-content/uploads/2010/05/legendpie-300x180.png" style="clear: both;" alt="" /></a></p>
<p><span id="more-933"></span>这个例子不仅展示了图例的显示，也展示了标签的样式的设定和饼图边缘阴影化。</p>
<p>－图例增加通过：BaseChart.addLegend</p>
<p>－改变标签样式使用：<span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;" class="Apple-style-span"><span style="font-family: verdana; font-size: 13px;" class="Apple-style-span">PieChart.setLabelFormat</span></span></p>
<p>－增加边缘阴影：<span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;" class="Apple-style-span"><span style="font-family: verdana; font-size: 13px;" class="Apple-style-span">PieChart.setSectorStyle</span></span></p>
<p><span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;" class="Apple-style-span"><span style="font-family: verdana; font-size: 13px;" class="Apple-style-span">代码：</span></span></p>
<p><span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;" class="Apple-style-span"><span style="font-family: verdana; font-size: 13px;" class="Apple-style-span"></p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
<span style="color: #ff7700;font-weight:bold;">from</span> pychartdir <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The data for the pie chart</span>
data = <span style="color: black;">&#91;</span><span style="color: #ff4500;">25</span>, <span style="color: #ff4500;">18</span>, <span style="color: #ff4500;">15</span>, <span style="color: #ff4500;">12</span>, <span style="color: #ff4500;">8</span>, <span style="color: #ff4500;">30</span>, <span style="color: #ff4500;">35</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The labels for the pie chart</span>
labels = <span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;Labor&quot;</span>, <span style="color: #483d8b;">&quot;Licenses&quot;</span>, <span style="color: #483d8b;">&quot;Taxes&quot;</span>, <span style="color: #483d8b;">&quot;Legal&quot;</span>, <span style="color: #483d8b;">&quot;Insurance&quot;</span>, <span style="color: #483d8b;">&quot;Facilities&quot;</span>,
    <span style="color: #483d8b;">&quot;Production&quot;</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Create a PieChart object of size 450 x 270 pixels</span>
c = PieChart<span style="color: black;">&#40;</span><span style="color: #ff4500;">450</span>, <span style="color: #ff4500;">270</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the center of the pie at (150, 100) and the radius to 80 pixels</span>
c.<span style="color: black;">setPieSize</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">150</span>, <span style="color: #ff4500;">135</span>, <span style="color: #ff4500;">100</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># add a legend box where the top left corner is at (330, 50)</span>
c.<span style="color: black;">addLegend</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">330</span>, <span style="color: #ff4500;">60</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># modify the sector label format to show percentages only</span>
c.<span style="color: black;">setLabelFormat</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;{percent}%&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the pie data and the pie labels</span>
c.<span style="color: black;">setData</span><span style="color: black;">&#40;</span>data, labels<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Use rounded edge shading, with a 1 pixel white (FFFFFF) border</span>
c.<span style="color: black;">setSectorStyle</span><span style="color: black;">&#40;</span>RoundedEdgeShading, 0xffffff, <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Output the chart</span>
c.<span style="color: black;">makeChart</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;legendpie.png&quot;</span><span style="color: black;">&#41;</span></pre></div></div>

<p></span></span></p>
<p>我们再来看看更为复杂一点的图例：</p>
<p><a href="http://pwwang.com/wp-content/uploads/2010/05/legendpie2.png"><img width="300" height="162" border="0" title="legendpie2" src="http://pwwang.com/wp-content/uploads/2010/05/legendpie2-300x162.png" style="clear: both;" alt="" /></a></p>
<p>我们看看这张图有些什么效果：背景颜色渐变、圆角图例框、软阴影、自定义区域颜色、区域阴影渐变、用CDML自定义区域标签、格式化的图例文字</p>
<p>－背景颜色渐变：BaseChart.linearGradientColor</p>
<p>－圆角图例框：BaseChart.setRoundedFrame</p>
<p>－软阴影：BaseChart.setDropShadow</p>
<p>－区域自定义颜色：BaseChart.setColors</p>
<p>－区域渐变阴影：PieChart.setSectorStyle</p>
<p>－自定义区域标签：PieChart.setLabelFormat（设置序号）、PieChart.setLabelStyle（设置样式）、Box.setBackground（标签加框）</p>
<p>－图例文字设置：用LegendBox的TextBox.setText，图例文字模板是用如下CDML描述的：</p>
<blockquote>
<p><span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;" class="Apple-style-span"><span style="font-family: 'courier new',courier; font-size: 13px;" class="Apple-style-span">&lt;*block,valign=top*&gt;{={sector}+1}.&lt;*advanceTo=22*&gt;&lt;*block,width=120*&gt;{label}&lt;*/*&gt;&lt;*block,width=40,halign=right*&gt;{percent}&lt;*/*&gt;%</span></span></p>
</blockquote>
<p><span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;" class="Apple-style-span"><span style="font-family: 'courier new',courier; font-size: 13px;" class="Apple-style-span">&lt;*block,valign=top*&gt; 表示图例中不同的部分都顶端对齐，这样图例第二部分可以多行显示<br />
</span></span></p>
<p><span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;" class="Apple-style-span"><span style="font-family: verdana; font-size: 13px;" class="Apple-style-span">{={sector}+1}.&lt;*advanceTo=22*&gt; 显示序号，并TAB到22px的位置（sector从0开始，所以要+1）<br />
</span></span></p>
<p><span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;" class="Apple-style-span"><span style="font-family: verdana; font-size: 13px;" class="Apple-style-span">&lt;*block,width=120*&gt;{label}&lt;*/*&gt; 在120px长的block中显示标签，如果标签文字长于120px，则多行显示<br />
</span></span></p>
<p><span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;" class="Apple-style-span"><span style="font-family: verdana; font-size: 13px;" class="Apple-style-span">&lt;*block,width=40,halign=right*&gt;{percent}&lt;*/*&gt;% 在40px长的block中显示百分比，并右对齐<br />
</span></span></p>
<p>&nbsp;</p>
<p><span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;" class="Apple-style-span"><span style="font-family: verdana; font-size: 13px;" class="Apple-style-span">代码：</span></span></p>
<p><span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;" class="Apple-style-span"><span style="font-family: verdana; font-size: 13px;" class="Apple-style-span"></p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
<span style="color: #ff7700;font-weight:bold;">from</span> pychartdir <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The data for the pie chart</span>
data = <span style="color: black;">&#91;</span><span style="color: #ff4500;">21</span>, <span style="color: #ff4500;">18</span>, <span style="color: #ff4500;">15</span>, <span style="color: #ff4500;">12</span>, <span style="color: #ff4500;">8</span>, <span style="color: #ff4500;">24</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The labels for the pie chart</span>
labels = <span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;Labor&quot;</span>, <span style="color: #483d8b;">&quot;Licenses&quot;</span>, <span style="color: #483d8b;">&quot;Taxes&quot;</span>, <span style="color: #483d8b;">&quot;Legal&quot;</span>, <span style="color: #483d8b;">&quot;Facilities&quot;</span>, <span style="color: #483d8b;">&quot;Production&quot;</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The colors to use for the sectors</span>
colors = <span style="color: black;">&#91;</span>0x66aaee, 0xeebb22, 0xbbbbbb, 0x8844ff, 0xdd2222, 0x009900<span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Create a PieChart object of size 600 x 320 pixels. Use a vertical gradient color</span>
<span style="color: #808080; font-style: italic;"># from light blue (99ccff) to white (ffffff) spanning the top 100 pixels as</span>
<span style="color: #808080; font-style: italic;"># background. Set border to grey (888888). Use rounded corners. Enable soft drop</span>
<span style="color: #808080; font-style: italic;"># shadow.</span>
c = PieChart<span style="color: black;">&#40;</span><span style="color: #ff4500;">600</span>, <span style="color: #ff4500;">320</span><span style="color: black;">&#41;</span>
c.<span style="color: black;">setBackground</span><span style="color: black;">&#40;</span>c.<span style="color: black;">linearGradientColor</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">100</span>, 0x99ccff, 0xffffff<span style="color: black;">&#41;</span>, 0x888888<span style="color: black;">&#41;</span>
c.<span style="color: black;">setRoundedFrame</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
c.<span style="color: black;">setDropShadow</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Add a title using 18 pts Times New Roman Bold Italic font. Add 16 pixels top margin</span>
<span style="color: #808080; font-style: italic;"># to the title.</span>
c.<span style="color: black;">addTitle</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Pie Chart With Legend Demonstration&quot;</span>, <span style="color: #483d8b;">&quot;timesbi.ttf&quot;</span>, <span style="color: #ff4500;">18</span><span style="color: black;">&#41;</span>.<span style="color: black;">setMargin2</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">0</span>,
    <span style="color: #ff4500;">16</span>, <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the center of the pie at (160, 165) and the radius to 110 pixels</span>
c.<span style="color: black;">setPieSize</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">160</span>, <span style="color: #ff4500;">165</span>, <span style="color: #ff4500;">110</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Draw the pie in 3D with a pie thickness of 25 pixels</span>
c.<span style="color: black;">set3D</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">25</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the pie data and the pie labels</span>
c.<span style="color: black;">setData</span><span style="color: black;">&#40;</span>data, labels<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the sector colors</span>
c.<span style="color: black;">setColors2</span><span style="color: black;">&#40;</span>DataColor, colors<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Use local gradient shading for the sectors</span>
c.<span style="color: black;">setSectorStyle</span><span style="color: black;">&#40;</span>LocalGradientShading<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Use the side label layout method, with the labels positioned 16 pixels from the pie</span>
<span style="color: #808080; font-style: italic;"># bounding box</span>
c.<span style="color: black;">setLabelLayout</span><span style="color: black;">&#40;</span>SideLayout, <span style="color: #ff4500;">16</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Show only the sector number as the sector label</span>
c.<span style="color: black;">setLabelFormat</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;{={sector}+1}&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the sector label style to Arial Bold 10pt, with a dark grey (444444) border</span>
c.<span style="color: black;">setLabelStyle</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;arialbd.ttf&quot;</span>, <span style="color: #ff4500;">10</span><span style="color: black;">&#41;</span>.<span style="color: black;">setBackground</span><span style="color: black;">&#40;</span>Transparent, 0x444444<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Add a legend box, with the center of the left side anchored at (330, 175), and</span>
<span style="color: #808080; font-style: italic;"># using 10 pts Arial Bold Italic font</span>
b = c.<span style="color: black;">addLegend</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">330</span>, <span style="color: #ff4500;">175</span>, <span style="color: #ff4500;">1</span>, <span style="color: #483d8b;">&quot;arialbi.ttf&quot;</span>, <span style="color: #ff4500;">10</span><span style="color: black;">&#41;</span>
b.<span style="color: black;">setAlignment</span><span style="color: black;">&#40;</span>Left<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the legend box border to dark grey (444444), and with rounded conerns</span>
b.<span style="color: black;">setBackground</span><span style="color: black;">&#40;</span>Transparent, 0x444444<span style="color: black;">&#41;</span>
b.<span style="color: black;">setRoundedCorners</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the legend box margin to 16 pixels, and the extra line spacing between the</span>
<span style="color: #808080; font-style: italic;"># legend entries as 5 pixels</span>
b.<span style="color: black;">setMargin</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">16</span><span style="color: black;">&#41;</span>
b.<span style="color: black;">setKeySpacing</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the legend box icon to have no border (border color same as fill color)</span>
b.<span style="color: black;">setKeyBorder</span><span style="color: black;">&#40;</span>SameAsMainColor<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the legend text to show the sector number, followed by a 120 pixels wide block</span>
<span style="color: #808080; font-style: italic;"># showing the sector label, and a 40 pixels wide block showing the percentage</span>
b.<span style="color: black;">setText</span><span style="color: black;">&#40;</span>
    <span style="color: #483d8b;">&quot;&lt;*block,valign=top*&gt;{={sector}+1}.&lt;*advanceTo=22*&gt;&lt;*block,width=120*&gt;{label}&quot;</span> \
    <span style="color: #483d8b;">&quot;&lt;*/*&gt;&lt;*block,width=40,halign=right*&gt;{percent}&lt;*/*&gt;%&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Output the chart</span>
c.<span style="color: black;">makeChart</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;legendpie2.png&quot;</span><span style="color: black;">&#41;</span></pre></div></div>

<p></span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://pwwang.com/2010/05/18/pychartdirector8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PyChartDirector中文教程[7]：饼图的标签</title>
		<link>http://pwwang.com/2010/05/13/pychartdirector_7_chartlabel/</link>
		<comments>http://pwwang.com/2010/05/13/pychartdirector_7_chartlabel/#comments</comments>
		<pubDate>Thu, 13 May 2010 08:26:38 +0000</pubDate>
		<dc:creator>pwwang</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[ChartDirector]]></category>

		<guid isPermaLink="false">http://pwwang.com/?p=922</guid>
		<description><![CDATA[&#160;

下面我们看看如何用不同的方式来显示饼图的标签

1. 侧边标签层

<span class="readmore"><a href="http://pwwang.com/2010/05/13/pychartdirector_7_chartlabel/" title="PyChartDirector中文教程[7]：饼图的标签">Read More: 3627 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>下面我们看看如何用不同的方式来显示饼图的标签</p>
<p><strong>1. 侧边标签层</strong></p>
<p>先看看效果图:</p>
<p><a href="http://pwwang.com/wp-content/uploads/2010/05/sidelabelpie.png"><img width="300" height="144" border="0" title="sidelabelpie" src="http://pwwang.com/wp-content/uploads/2010/05/sidelabelpie-300x144.png" style="clear: both;" alt="" /></a></p>
<p><span id="more-922"></span>标签的效果: 金属背景颜色, 圆角, 玻璃阴影效果</p>
<p>侧边标签层的标签将放置在图表的左侧和右侧</p>
<p>侧边标签层有一个好处, 那就是标签会自动上下排列, 防止交叠.</p>
<p>&nbsp;</p>
<p>金色的背景由 pychartdir.goldColor产生</p>
<p>粉色金属背景由pychartdir.metalColor产生, 用Box.setBackground来设置标题TextBox的背景颜色</p>
<p>侧边标签层由PieChart.setLabelLayout来指定</p>
<p>玻璃效果由pychartdir.glassEffect来增加, 用Box.setBackground来分别指定</p>
<p>圆角标签用Box.setRoundedCorners来设置</p>
<p>&nbsp;</p>
<p>如果数据中有些排序好的小值, 这个小值代表的块将会被放在一起, 这样标签就不需要太多的移动, 这个小值块更多的是在左边或者右边,而不是上边或者下边.</p>
<p>如果数据是降序排列的, 那么图的初始角度是顺时针135度,来保证那些小值块在45-135之间(在图的右边),&nbsp; 如果是升序, 则初始角度是45度.</p>
<p>代码:</p>
<p>&nbsp;</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
<span style="color: #ff7700;font-weight:bold;">from</span> pychartdir <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The data for the pie chart</span>
data = <span style="color: black;">&#91;</span><span style="color: #ff4500;">35</span>, <span style="color: #ff4500;">30</span>, <span style="color: #ff4500;">25</span>, <span style="color: #ff4500;">7</span>, <span style="color: #ff4500;">6</span>, <span style="color: #ff4500;">5</span>, <span style="color: #ff4500;">4</span>, <span style="color: #ff4500;">3</span>, <span style="color: #ff4500;">2</span>, <span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The labels for the pie chart</span>
labels = <span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;Labor&quot;</span>, <span style="color: #483d8b;">&quot;Production&quot;</span>, <span style="color: #483d8b;">&quot;Facilities&quot;</span>, <span style="color: #483d8b;">&quot;Taxes&quot;</span>, <span style="color: #483d8b;">&quot;Misc&quot;</span>, <span style="color: #483d8b;">&quot;Legal&quot;</span>, <span style="color: #483d8b;">&quot;Insurance&quot;</span>,
    <span style="color: #483d8b;">&quot;Licenses&quot;</span>, <span style="color: #483d8b;">&quot;Transport&quot;</span>, <span style="color: #483d8b;">&quot;Interest&quot;</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Create a PieChart object of size 560 x 270 pixels, with a golden background and a 1</span>
<span style="color: #808080; font-style: italic;"># pixel 3D border</span>
c = PieChart<span style="color: black;">&#40;</span><span style="color: #ff4500;">560</span>, <span style="color: #ff4500;">270</span>, goldColor<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>, -<span style="color: #ff4500;">1</span>, <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Add a title box using 15 pts Times Bold Italic font and metallic pink background</span>
<span style="color: #808080; font-style: italic;"># color</span>
c.<span style="color: black;">addTitle</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Project Cost Breakdown&quot;</span>, <span style="color: #483d8b;">&quot;timesbi.ttf&quot;</span>, <span style="color: #ff4500;">15</span><span style="color: black;">&#41;</span>.<span style="color: black;">setBackground</span><span style="color: black;">&#40;</span>metalColor<span style="color: black;">&#40;</span>
    0xff9999<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the center of the pie at (280, 135) and the radius to 110 pixels</span>
c.<span style="color: black;">setPieSize</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">280</span>, <span style="color: #ff4500;">135</span>, <span style="color: #ff4500;">110</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Draw the pie in 3D with 20 pixels 3D depth</span>
c.<span style="color: black;">set3D</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">20</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Use the side label layout method</span>
c.<span style="color: black;">setLabelLayout</span><span style="color: black;">&#40;</span>SideLayout<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the label box background color the same as the sector color, with glass effect,</span>
<span style="color: #808080; font-style: italic;"># and with 5 pixels rounded corners</span>
t = c.<span style="color: black;">setLabelStyle</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
t.<span style="color: black;">setBackground</span><span style="color: black;">&#40;</span>SameAsMainColor, Transparent, glassEffect<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
t.<span style="color: black;">setRoundedCorners</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the border color of the sector the same color as the fill color. Set the line</span>
<span style="color: #808080; font-style: italic;"># color of the join line to black (0x0)</span>
c.<span style="color: black;">setLineColor</span><span style="color: black;">&#40;</span>SameAsMainColor, 0x000000<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the start angle to 135 degrees may improve layout when there are many small</span>
<span style="color: #808080; font-style: italic;"># sectors at the end of the data array (that is, data sorted in descending order). It</span>
<span style="color: #808080; font-style: italic;"># is because this makes the small sectors position near the horizontal axis, where</span>
<span style="color: #808080; font-style: italic;"># the text label has the least tendency to overlap. For data sorted in ascending</span>
<span style="color: #808080; font-style: italic;"># order, a start angle of 45 degrees can be used instead.</span>
c.<span style="color: black;">setStartAngle</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">135</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the pie data and the pie labels</span>
c.<span style="color: black;">setData</span><span style="color: black;">&#40;</span>data, labels<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Output the chart</span>
c.<span style="color: black;">makeChart</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;sidelabelpie.png&quot;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>&nbsp;</p>
<p><strong>2. 环形标签层</strong></p>
<p>看效果图:</p>
<p>&nbsp;<img width="300" height="300" border="0" title="circlelabelpie0" src="http://pwwang.com/wp-content/uploads/2010/05/circlelabelpie0-300x300.png" alt="" /> <a href="http://pwwang.com/wp-content/uploads/2010/05/circlelabelpie1.png"><img width="300" height="300" border="0" title="circlelabelpie1" src="http://pwwang.com/wp-content/uploads/2010/05/circlelabelpie1-300x300.png" style="clear: both;" alt="" /></a></p>
<p>&nbsp;这种环形标签有几种效果, 默认地是像最开始的例子那样,在图表的外面,紧挨着图.</p>
<p>Pie.setLabelPos可以用来控制标签与圆周之间的距离. 并可以在圆周和标签之间添加连接线, 当标签比较远的时候连接线是很有用的.</p>
<p>如果标签与圆周之间的距离是负值, 那么标签将会显示在圆周之内.</p>
<p>代码:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
<span style="color: #ff7700;font-weight:bold;">from</span> pychartdir <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> createChart<span style="color: black;">&#40;</span>img<span style="color: black;">&#41;</span> :
&nbsp;
    <span style="color: #808080; font-style: italic;"># The data for the pie chart</span>
    data = <span style="color: black;">&#91;</span><span style="color: #ff4500;">42</span>, <span style="color: #ff4500;">18</span>, <span style="color: #ff4500;">8</span><span style="color: black;">&#93;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># The labels for the pie chart</span>
    labels = <span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;Agree&quot;</span>, <span style="color: #483d8b;">&quot;Disagree&quot;</span>, <span style="color: #483d8b;">&quot;Not Sure&quot;</span><span style="color: black;">&#93;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># The colors to use for the sectors</span>
    colors = <span style="color: black;">&#91;</span>0x66ff66, 0xff6666, 0xffff00<span style="color: black;">&#93;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># Create a PieChart object of size 300 x 300 pixels. Set the background to a</span>
    <span style="color: #808080; font-style: italic;"># gradient color from blue (aaccff) to sky blue (ffffff), with a grey (888888)</span>
    <span style="color: #808080; font-style: italic;"># border. Use rounded corners and soft drop shadow.</span>
    c = PieChart<span style="color: black;">&#40;</span><span style="color: #ff4500;">300</span>, <span style="color: #ff4500;">300</span><span style="color: black;">&#41;</span>
    c.<span style="color: black;">setBackground</span><span style="color: black;">&#40;</span>c.<span style="color: black;">linearGradientColor</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">0</span>, c.<span style="color: black;">getHeight</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> / <span style="color: #ff4500;">2</span>, 0xaaccff,
        0xffffff<span style="color: black;">&#41;</span>, 0x888888<span style="color: black;">&#41;</span>
    c.<span style="color: black;">setRoundedFrame</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    c.<span style="color: black;">setDropShadow</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> img == <span style="color: #483d8b;">&quot;0&quot;</span> :
    <span style="color: #808080; font-style: italic;">#============================================================</span>
    <span style="color: #808080; font-style: italic;">#    Draw a pie chart where the label is on top of the pie</span>
    <span style="color: #808080; font-style: italic;">#============================================================</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># Set the center of the pie at (150, 150) and the radius to 120 pixels</span>
        c.<span style="color: black;">setPieSize</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">150</span>, <span style="color: #ff4500;">150</span>, <span style="color: #ff4500;">120</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># Set the label position to -40 pixels from the perimeter of the pie (-ve</span>
        <span style="color: #808080; font-style: italic;"># means label is inside the pie)</span>
        c.<span style="color: black;">setLabelPos</span><span style="color: black;">&#40;</span>-<span style="color: #ff4500;">40</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">else</span> :
    <span style="color: #808080; font-style: italic;">#============================================================</span>
    <span style="color: #808080; font-style: italic;">#    Draw a pie chart where the label is outside the pie</span>
    <span style="color: #808080; font-style: italic;">#============================================================</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># Set the center of the pie at (150, 150) and the radius to 80 pixels</span>
        c.<span style="color: black;">setPieSize</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">150</span>, <span style="color: #ff4500;">150</span>, <span style="color: #ff4500;">80</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># Set the sector label position to be 20 pixels from the pie. Use a join line</span>
        <span style="color: #808080; font-style: italic;"># to connect the labels to the sectors.</span>
        c.<span style="color: black;">setLabelPos</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">20</span>, LineColor<span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
    <span style="color: #808080; font-style: italic;"># Set the pie data and the pie labels</span>
    c.<span style="color: black;">setData</span><span style="color: black;">&#40;</span>data, labels<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># Set the sector colors</span>
    c.<span style="color: black;">setColors2</span><span style="color: black;">&#40;</span>DataColor, colors<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># Use local gradient shading, with a 1 pixel semi-transparent black (bb000000)</span>
    <span style="color: #808080; font-style: italic;"># border</span>
    c.<span style="color: black;">setSectorStyle</span><span style="color: black;">&#40;</span>LocalGradientShading, 0xbb000000L, <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># Output the chart</span>
    c.<span style="color: black;">makeChart</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;circlelabelpie%s.png&quot;</span> <span style="color: #66cc66;">%</span> img<span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
createChart<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;0&quot;</span><span style="color: black;">&#41;</span>
createChart<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;1&quot;</span><span style="color: black;">&#41;</span></pre></div></div>
</p>
]]></content:encoded>
			<wfw:commentRss>http://pwwang.com/2010/05/13/pychartdirector_7_chartlabel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PyChartDirector中文教程[6]：多深度饼图</title>
		<link>http://pwwang.com/2010/05/10/pychartdirector_note_mdepthpie/</link>
		<comments>http://pwwang.com/2010/05/10/pychartdirector_note_mdepthpie/#comments</comments>
		<pubDate>Mon, 10 May 2010 01:22:55 +0000</pubDate>
		<dc:creator>pwwang</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[ChartDirector]]></category>

		<guid isPermaLink="false">http://pwwang.com/?p=914</guid>
		<description><![CDATA[&#160;

我们扩展了一下开始画的简单的饼图, 那还能不能再扩展一下呢, 

能否画出不同尝试的3D效果呢?

<span class="readmore"><a href="http://pwwang.com/2010/05/10/pychartdirector_note_mdepthpie/" title="PyChartDirector中文教程[6]：多深度饼图">Read More: 1009 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>我们扩展了一下开始画的简单的饼图, 那还能不能再扩展一下呢, </p>
<p>能否画出不同尝试的3D效果呢?</p>
<p>我们看看这个效果图:</p>
<p><a href="http://pwwang.com/wp-content/uploads/2010/05/multidepthpie.png"><img width="300" height="250" border="0" title="multidepthpie" src="http://pwwang.com/wp-content/uploads/2010/05/multidepthpie-300x250.png" style="clear: both;" alt="" /></a></p>
<p><span id="more-914"></span></p>
<p>在这个例子中, 不再使用PieChart.set3D来画3D效果, 而是通过PieChart.set3D2来画图.</p>
<p>通过一个整数数组来指定不同区域的高度.</p>
<p>源代码如下:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
<span style="color: #ff7700;font-weight:bold;">from</span> pychartdir <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The data for the pie chart</span>
data = <span style="color: black;">&#91;</span><span style="color: #ff4500;">72</span>, <span style="color: #ff4500;">18</span>, <span style="color: #ff4500;">15</span>, <span style="color: #ff4500;">12</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The labels for the pie chart</span>
labels = <span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;Labor&quot;</span>, <span style="color: #483d8b;">&quot;Machinery&quot;</span>, <span style="color: #483d8b;">&quot;Facilities&quot;</span>, <span style="color: #483d8b;">&quot;Computers&quot;</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The depths for the sectors</span>
depths = <span style="color: black;">&#91;</span><span style="color: #ff4500;">30</span>, <span style="color: #ff4500;">20</span>, <span style="color: #ff4500;">10</span>, <span style="color: #ff4500;">10</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Create a PieChart object of size 360 x 300 pixels, with a light blue (DDDDFF)</span>
<span style="color: #808080; font-style: italic;"># background and a 1 pixel 3D border</span>
c = PieChart<span style="color: black;">&#40;</span><span style="color: #ff4500;">360</span>, <span style="color: #ff4500;">300</span>, 0xddddff, -<span style="color: #ff4500;">1</span>, <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the center of the pie at (180, 175) and the radius to 100 pixels</span>
c.<span style="color: black;">setPieSize</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">180</span>, <span style="color: #ff4500;">175</span>, <span style="color: #ff4500;">100</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Add a title box using 15 pts Times Bold Italic font and blue (AAAAFF) as background</span>
<span style="color: #808080; font-style: italic;"># color</span>
c.<span style="color: black;">addTitle</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Project Cost Breakdown&quot;</span>, <span style="color: #483d8b;">&quot;timesbi.ttf&quot;</span>, <span style="color: #ff4500;">15</span><span style="color: black;">&#41;</span>.<span style="color: black;">setBackground</span><span style="color: black;">&#40;</span>0xaaaaff<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the pie data and the pie labels</span>
c.<span style="color: black;">setData</span><span style="color: black;">&#40;</span>data, labels<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Draw the pie in 3D with variable 3D depths, 指定不同区域的高度</span>
c.<span style="color: black;">set3D2</span><span style="color: black;">&#40;</span>depths<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the start angle to 225 degrees may improve layout when the depths of the sector</span>
<span style="color: #808080; font-style: italic;"># are sorted in descending order, because it ensures the tallest sector is at the</span>
<span style="color: #808080; font-style: italic;"># back.</span>
c.<span style="color: black;">setStartAngle</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">225</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Output the chart</span>
c.<span style="color: black;">makeChart</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;multidepthpie.png&quot;</span><span style="color: black;">&#41;</span></pre></div></div>
</p>
]]></content:encoded>
			<wfw:commentRss>http://pwwang.com/2010/05/10/pychartdirector_note_mdepthpie/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PyChartDirector中文教程[5]：3D饼图</title>
		<link>http://pwwang.com/2010/05/07/pychartdirector_note_3dpie/</link>
		<comments>http://pwwang.com/2010/05/07/pychartdirector_note_3dpie/#comments</comments>
		<pubDate>Fri, 07 May 2010 01:08:53 +0000</pubDate>
		<dc:creator>pwwang</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[ChartDirector]]></category>

		<guid isPermaLink="false">http://pwwang.com/?p=912</guid>
		<description><![CDATA[&#160;

前面我们画了一个非常简单的饼状图, 接下来,我们来扩展一下这个饼状图吧,

先看看我们扩展的这个3D饼图:

<span class="readmore"><a href="http://pwwang.com/2010/05/07/pychartdirector_note_3dpie/" title="PyChartDirector中文教程[5]：3D饼图">Read More: 710 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>前面我们画了一个非常简单的饼状图, 接下来,我们来扩展一下这个饼状图吧,</p>
<p>先看看我们扩展的这个3D饼图:</p>
<p>&nbsp;</p>
<p><a href="http://pwwang.com/wp-content/uploads/2010/05/threedpie.png"><img width="300" height="250" border="0" title="threedpie" src="http://pwwang.com/wp-content/uploads/2010/05/threedpie-300x250.png" style="clear: both;" alt="" /></a></p>
<p>&nbsp;</p>
<p><span id="more-912"></span>这个例子对先一个例子进行了扩展:</p>
<blockquote>
<p>用BaseChart.addTitle添加了标题</p>
<p>用PieChart.set3D画3D图</p>
<p>用PieChart.setExplode展开其中的一块区域</p>
</blockquote>
<p>源代码:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
<span style="color: #ff7700;font-weight:bold;">from</span> pychartdir <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The data for the pie chart</span>
data = <span style="color: black;">&#91;</span><span style="color: #ff4500;">25</span>, <span style="color: #ff4500;">18</span>, <span style="color: #ff4500;">15</span>, <span style="color: #ff4500;">12</span>, <span style="color: #ff4500;">8</span>, <span style="color: #ff4500;">30</span>, <span style="color: #ff4500;">35</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The labels for the pie chart</span>
labels = <span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;Labor&quot;</span>, <span style="color: #483d8b;">&quot;Licenses&quot;</span>, <span style="color: #483d8b;">&quot;Taxes&quot;</span>, <span style="color: #483d8b;">&quot;Legal&quot;</span>, <span style="color: #483d8b;">&quot;Insurance&quot;</span>, <span style="color: #483d8b;">&quot;Facilities&quot;</span>,
    <span style="color: #483d8b;">&quot;Production&quot;</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Create a PieChart object of size 360 x 300 pixels</span>
c = PieChart<span style="color: black;">&#40;</span><span style="color: #ff4500;">360</span>, <span style="color: #ff4500;">300</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the center of the pie at (180, 140) and the radius to 100 pixels</span>
c.<span style="color: black;">setPieSize</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">180</span>, <span style="color: #ff4500;">140</span>, <span style="color: #ff4500;">100</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Add a title to the pie chart, 添加标题</span>
c.<span style="color: black;">addTitle</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Project Cost Breakdown&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Draw the pie in 3D, 3D模式</span>
c.<span style="color: black;">set3D</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the pie data and the pie labels</span>
c.<span style="color: black;">setData</span><span style="color: black;">&#40;</span>data, labels<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Explode the 1st sector (index = 0)</span>
c.<span style="color: black;">setExplode</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>  <span style="color: #808080; font-style: italic;">#展开第一块区域</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Output the chart</span>
c.<span style="color: black;">makeChart</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;threedpie.png&quot;</span><span style="color: black;">&#41;</span></pre></div></div>
</p>
]]></content:encoded>
			<wfw:commentRss>http://pwwang.com/2010/05/07/pychartdirector_note_3dpie/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PyChartDirector中文教程[3]：嵌入网页</title>
		<link>http://pwwang.com/2010/05/01/pychartdirector_note_3/</link>
		<comments>http://pwwang.com/2010/05/01/pychartdirector_note_3/#comments</comments>
		<pubDate>Sat, 01 May 2010 08:12:14 +0000</pubDate>
		<dc:creator>pwwang</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[ChartDirector]]></category>

		<guid isPermaLink="false">http://pwwang.com/?p=901</guid>
		<description><![CDATA[&#160;

前面, 我们画了第一个图, 并把它保存到了文件, 下面我们看看怎么把它直接插入到网页中:



<span class="readmore"><a href="http://pwwang.com/2010/05/01/pychartdirector_note_3/" title="PyChartDirector中文教程[3]：嵌入网页">Read More: 973 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>前面, 我们画了第一个图, 并把它保存到了文件, 下面我们看看怎么把它直接插入到网页中:</p>
<p><span id="more-901"></span></p>
<p>文件: pythondemo_cgi\simplebar.py</p>
<p>&nbsp;</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
<span style="color: #ff7700;font-weight:bold;">from</span> pychartdir <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The data for the bar chart</span>
data = <span style="color: black;">&#91;</span><span style="color: #ff4500;">85</span>, <span style="color: #ff4500;">156</span>, <span style="color: #ff4500;">179.5</span>, <span style="color: #ff4500;">211</span>, <span style="color: #ff4500;">123</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The labels for the bar chart</span>
labels = <span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;Mon&quot;</span>, <span style="color: #483d8b;">&quot;Tue&quot;</span>, <span style="color: #483d8b;">&quot;Wed&quot;</span>, <span style="color: #483d8b;">&quot;Thu&quot;</span>, <span style="color: #483d8b;">&quot;Fri&quot;</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Create a XYChart object of size 250 x 250 pixels</span>
c = XYChart<span style="color: black;">&#40;</span><span style="color: #ff4500;">250</span>, <span style="color: #ff4500;">250</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the plotarea at (30, 20) and of size 200 x 200 pixels</span>
c.<span style="color: black;">setPlotArea</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">30</span>, <span style="color: #ff4500;">20</span>, <span style="color: #ff4500;">200</span>, <span style="color: #ff4500;">200</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Add a bar chart layer using the given data</span>
c.<span style="color: black;">addBarLayer</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the labels on the x axis.</span>
c.<span style="color: black;">xAxis</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">setLabels</span><span style="color: black;">&#40;</span>labels<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Output the chart</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Content-type: image/png<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
binaryPrint<span style="color: black;">&#40;</span>c.<span style="color: black;">makeChart2</span><span style="color: black;">&#40;</span>PNG<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>&nbsp;</p>
<p>代码中, 前面部分和hello world的例子相同, 只有后面这两句有所不同:</p>
<p>&nbsp;</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Content-type: image/png<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
binaryPrint<span style="color: black;">&#40;</span>c.<span style="color: black;">makeChart2</span><span style="color: black;">&#40;</span>PNG<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>&nbsp;</p>
<p>这两句是输出一个MIME类型的头部, 并输出一个准备送往浏览器的二进制图片.</p>
<p>上面的代码只是生成了一个二进制图片,那么我们如果把它插入到网页中呢?</p>
<p>其实和普通的图片的插入方法是一样的:</p>
<p>&nbsp;</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;HTML&gt;
&lt;BODY&gt;
&nbsp;
&lt;h1&gt;Hello World!&lt;/h1&gt;
&lt;p&gt;Hi, this is my first web page with ChartDirector charts.&lt;/p&gt;
&nbsp;
&lt;IMG SRC=&quot;http://aaa.bbb.ccc.ddd/cgi-bin/pythondemo_cgi/simplebar.py&quot;&gt;
&nbsp;
More HTML elements ......
&nbsp;
&lt;/BODY&gt;
&lt;/HTML&gt;</pre></div></div>

<p>&nbsp;</p>
<p>&nbsp;在后面的例子中, 我们将不再例举CGI的例子, </p>
<p>因为只要将保存成图片的例子最后的makechart改成生成二进制图片的代码就行了</p>
]]></content:encoded>
			<wfw:commentRss>http://pwwang.com/2010/05/01/pychartdirector_note_3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PyChartDirector中文教程[2]：Hello, world!</title>
		<link>http://pwwang.com/2010/04/29/pychartdirector_note_2/</link>
		<comments>http://pwwang.com/2010/04/29/pychartdirector_note_2/#comments</comments>
		<pubDate>Thu, 29 Apr 2010 05:47:33 +0000</pubDate>
		<dc:creator>pwwang</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[ChartDirector]]></category>

		<guid isPermaLink="false">http://pwwang.com/?p=894</guid>
		<description><![CDATA[&#160;

&#160;前面我们已经了解了ChartDirector，也从我给出的图表中感受了它的强大，它所支持的图表类型已经基本上能满足我们的要求。

那么我们下面来看一下ChartDirector的Hello, world程序（当然不是打印一个Hello world，而是画一个简单的图表，如果你要那么认为，我只能表示无语凝噎。。。）

<span class="readmore"><a href="http://pwwang.com/2010/04/29/pychartdirector_note_2/" title="PyChartDirector中文教程[2]：Hello, world!">Read More: 1105 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>&nbsp;前面我们已经了解了ChartDirector，也从我给出的图表中感受了它的强大，它所支持的图表类型已经基本上能满足我们的要求。</p>
<p>那么我们下面来看一下ChartDirector的Hello, world程序（当然不是打印一个Hello world，而是画一个简单的图表，如果你要那么认为，我只能表示无语凝噎。。。）</p>
<p>我们要画的图就是我上一章给出的第一个图，一个简单的柱状图，我们再来看看它的美貌：</p>
<p><a href="http://pwwang.com/wp-content/uploads/2010/04/simplebar.png"><img title="simplebar" width="250" height="250" border="0" style="clear:both" alt="" src="http://pwwang.com/wp-content/uploads/2010/04/simplebar.png" /></a></p>
<p><span id="more-894"></span>让我们来看看这个图是怎么画的吧：</p>
<p>&nbsp;</p>
<p>&nbsp;</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
<span style="color: #ff7700;font-weight:bold;">from</span> pychartdir <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The data for the bar chart</span>
data = <span style="color: black;">&#91;</span><span style="color: #ff4500;">85</span>, <span style="color: #ff4500;">156</span>, <span style="color: #ff4500;">179.5</span>, <span style="color: #ff4500;">211</span>, <span style="color: #ff4500;">123</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># The labels for the bar chart</span>
labels = <span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;Mon&quot;</span>, <span style="color: #483d8b;">&quot;Tue&quot;</span>, <span style="color: #483d8b;">&quot;Wed&quot;</span>, <span style="color: #483d8b;">&quot;Thu&quot;</span>, <span style="color: #483d8b;">&quot;Fri&quot;</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Create a XYChart object of size 250 x 250 pixels</span>
c = XYChart<span style="color: black;">&#40;</span><span style="color: #ff4500;">250</span>, <span style="color: #ff4500;">250</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the plotarea at (30, 20) and of size 200 x 200 pixels</span>
c.<span style="color: black;">setPlotArea</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">30</span>, <span style="color: #ff4500;">20</span>, <span style="color: #ff4500;">200</span>, <span style="color: #ff4500;">200</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Add a bar chart layer using the given data</span>
c.<span style="color: black;">addBarLayer</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set the labels on the x axis.</span>
c.<span style="color: black;">xAxis</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">setLabels</span><span style="color: black;">&#40;</span>labels<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Output the chart</span>
c.<span style="color: black;">makeChart</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;simplebar.png&quot;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>&nbsp;</p>
<p>解释一下代码：</p>
<p>&nbsp;</p>
<blockquote>
<pre><strong>from pychartdir import *</strong></pre>
<div>导入pychardir模块</div>
<pre><strong>c = XYChart(250, 250)</strong></pre>
<p>ChartDirector中创建一个图表对象的第一步。在这个例子中，创建了一个250X250像素的XYChart对象。在ChartDirector中XYChart表示任何有x轴和y轴的图表，就像我们画的图一样。</p>
<pre><strong>c.setPlotArea(30, 30, 200, 200)</strong></pre>
<p>第二步是指定画图的位置和大小，四个参数分别是x坐标（left），y坐标（top），长度和宽度。这里要注意的是你的x+width不要超过了你设置的图表的总宽度，还要预留一些位置给文字标记。</p>
<pre><strong>c.addBarLayer(data)</strong></pre>
<p>上面的这个代码将柱状加到图表中。在ChartDirector中，所有的xy图表类型都用一个层来表现。一个XYChart可以包含多个层。</p>
<pre><strong>c.xAxis().setLabels(labels)</strong></pre>
<p>设置X轴的标签。</p>
<pre><strong>c.makeChart(&quot;simplebar.png&quot;)</strong></pre>
<p>保存到文件。<br />
支持的类型：PNG, JPG, GIF, BMP 和WBMP.</p>
</blockquote>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://pwwang.com/2010/04/29/pychartdirector_note_2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PyChartDirector中文教程[1]：What?</title>
		<link>http://pwwang.com/2010/04/26/pychartdirector_note_1/</link>
		<comments>http://pwwang.com/2010/04/26/pychartdirector_note_1/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 07:26:22 +0000</pubDate>
		<dc:creator>pwwang</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[ChartDirector]]></category>

		<guid isPermaLink="false">http://pwwang.com/?p=880</guid>
		<description><![CDATA[&#160;

ChartDirector是一个商业插件，但是。。。你懂的

使用起来也比较简单，这是我自己的一个学习过程，E文好的童鞋，可以看它自带的文档。

<span class="readmore"><a href="http://pwwang.com/2010/04/26/pychartdirector_note_1/" title="PyChartDirector中文教程[1]：What?">Read More: 872 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<div>&nbsp;</div>
<div>ChartDirector是一个商业插件，但是。。。你懂的</div>
<div>使用起来也比较简单，这是我自己的一个学习过程，E文好的童鞋，可以看它自带的文档。</div>
<div>&nbsp;</div>
<div>安装的话就把lib设置到系统路径或者把lib下的东西copy到python的lib文件夹下。</div>
<div>&nbsp;</div>
<div>展示一下它画出的图吧</div>
<div><span id="more-880"></span></div>
<div>&nbsp;</div>
<div>&nbsp;
<a href='http://pwwang.com/2010/04/26/pychartdirector_note_1/simplebar/' title='simplebar'><img width="150" height="150" src="http://pwwang.com/wp-content/uploads/2010/04/simplebar-150x150.png" class="attachment-thumbnail" alt="simplebar" title="simplebar" /></a>
<a href='http://pwwang.com/2010/04/26/pychartdirector_note_1/anglepie0/' title='anglepie0'><img width="150" height="150" src="http://pwwang.com/wp-content/uploads/2010/04/anglepie0-150x150.png" class="attachment-thumbnail" alt="anglepie0" title="anglepie0" /></a>
<a href='http://pwwang.com/2010/04/26/pychartdirector_note_1/multiaxes/' title='multiaxes'><img width="150" height="150" src="http://pwwang.com/wp-content/uploads/2010/04/multiaxes-150x150.png" class="attachment-thumbnail" alt="multiaxes" title="multiaxes" /></a>
<a href='http://pwwang.com/2010/04/26/pychartdirector_note_1/surfaceperspective0/' title='surfaceperspective0'><img width="150" height="150" src="http://pwwang.com/wp-content/uploads/2010/04/surfaceperspective0-150x150.jpg" class="attachment-thumbnail" alt="surfaceperspective0" title="surfaceperspective0" /></a>
<a href='http://pwwang.com/2010/04/26/pychartdirector_note_1/polarzones2/' title='polarzones2'><img width="150" height="150" src="http://pwwang.com/wp-content/uploads/2010/04/polarzones2-150x150.png" class="attachment-thumbnail" alt="polarzones2" title="polarzones2" /></a>
<a href='http://pwwang.com/2010/04/26/pychartdirector_note_1/rotatedpyramid/' title='rotatedpyramid'><img width="150" height="150" src="http://pwwang.com/wp-content/uploads/2010/04/rotatedpyramid-150x150.png" class="attachment-thumbnail" alt="rotatedpyramid" title="rotatedpyramid" /></a>
<a href='http://pwwang.com/2010/04/26/pychartdirector_note_1/roundmeter/' title='roundmeter'><img width="150" height="150" src="http://pwwang.com/wp-content/uploads/2010/04/roundmeter-150x150.png" class="attachment-thumbnail" alt="roundmeter" title="roundmeter" /></a>
</div>
<div>&nbsp;</div>
<div><b><span>1.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></b><b>什么是ChartDirector</b><b>， </b><b>有什么特点：</b></div>
<div>&nbsp;</div>
<div style="margin-left: 40px; ">强大的画图插件，用来创建专业的图表用于web和windows程序。</div>
<div style="margin-left: 40px; ">一些特点，什么简单易用就不列了：</div>
<div style="margin-left: 40px; ">图表类型多样（包括pie, donut, bar, line, spline, step-line, trending, curve-fitting, inter-line coloring, area, scatter, bubble, floating box, box-whisker, waterfall, finance, gantt, vector, contour, heat map, surface, radar, polar line, polar area, polar spline, polar scatter, polar bubble, polar vector, rose, pyramid, cone and funnel，所有的类型支持XY轴交换，部分支持3D效果），</div>
<div style="margin-left: 40px; ">支持AJAX图表更新</div>
<div><b>&nbsp;</b></div>
<div><b><span>2.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></b><b>支持的语言</b></div>
<p style="margin-left: 40px; ">ASP / COM /      Visual Basic / VBScript / JScript</p>
<p style="margin-left: 40px; ">.NET (C#,      VB.NET, C++/CLI, JScript.NET, J#)</p>
<p style="margin-left: 40px; ">Java</p>
<p style="margin-left: 40px; ">PHP</p>
<p style="margin-left: 40px; ">Perl</p>
<p style="margin-left: 40px; ">Python</p>
<p style="margin-left: 40px; ">Ruby</p>
<p style="margin-left: 40px; ">ColdFusion</p>
<p style="margin-left: 40px; ">C++</p>
<div><b><span>3.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></b><b>支持的平台</b></div>
<div style="margin-left: 40px; ">Java版本不依赖平台</div>
<div style="margin-left: 40px; ">ChartDirector for ASP/COM/VB and .NET： Windows 2000/2003/2008/Vista/NT/XP.</div>
<div style="margin-left: 40px; ">ChartDirector for PHP, Perl, Python, Ruby and C++： Windows 2000/2003/2008/Vista/NT/XP, Linux, FreeBSD, Mac OS X and Solaris.</div>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://pwwang.com/2010/04/26/pychartdirector_note_1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[转]Django模板</title>
		<link>http://pwwang.com/2010/03/26/django_templates/</link>
		<comments>http://pwwang.com/2010/03/26/django_templates/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 01:35:02 +0000</pubDate>
		<dc:creator>pwwang</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://pwwang.com/?p=868</guid>
		<description><![CDATA[原文出处：http://www.woodpecker.org.cn/obp/django/django-faq/templates.html

Django 模板语言: 写给模板作者



<span class="readmore"><a href="http://pwwang.com/2010/03/26/django_templates/" title="[转]Django模板">Read More: 14441 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<div class="document" id="django">
<p>原文出处：<a href="http://www.woodpecker.org.cn/obp/django/django-faq/templates.html">http://www.woodpecker.org.cn/obp/django/django-faq/templates.html</a></p>
<h1 class="title">Django 模板语言: 写给模板作者</h1>
<table class="docinfo" rules="none" frame="void">
<colgroup>
<col class="docinfo-name" />
<col class="docinfo-content" /></colgroup>
<tbody valign="top">
<tr class="field">
<th class="docinfo-name">作者:</th>
<td class="field-body">Django 团队</td>
</tr>
<tr class="field">
<th class="docinfo-name">译者:</th>
<td class="field-body">weizhong2004@gmail.com</td>
</tr>
<tr class="field">
<th class="docinfo-name">翻译开始日期:</th>
<td class="field-body">2006-04-06</td>
</tr>
<tr class="field">
<th class="docinfo-name">翻译完成日期:</th>
<td class="field-body">2006-04-07</td>
</tr>
<tr class="field">
<th class="docinfo-name">更新日期:</th>
<td class="field-body">2006-07-03</td>
</tr>
<tr class="field">
<th class="docinfo-name">原文版本:</th>
<td class="field-body">3185</td>
</tr>
</tbody>
</table>
<p>Django 的模板语言的设计原则在动力和易用性之间取得均衡.(功能要足够强大，还要容易使用), 如果你以前使用过 HTML,你会觉得很容易上手.如果有其它基于文本的模板语言的经验, 比如 Smarty 或 CheetahTemplate, 你会觉得..使用django模板..就象在自己家里一样.</p>
<p><span id="more-868"></span></p>
<div class="section">
<h1><a id="templates" name="templates">Templates</a></h1>
<p>一个模板就是一个文本文件. 通过模板可以生成任意的基于文本的格式文件(HTML, XML, CSV, etc.).</p>
<p>一个模板包含 <strong>变量</strong>, 当模板被求值时,这些变量就被它们的值代替.而 <strong>标签</strong> 则控制着模板的逻辑.</p>
<p>下面是一个最小化的模板,它演示了某些基本概念. 其中的每个元素都会在本文档的后面部分被详细解释.:</p>
<pre class="literal-block">

{% extends &quot;base_generic.html&quot; %}

{% block title %}{{ section.title }}{% endblock %}

{% block content %}
&lt;h1&gt;{{ section.title }}&lt;/h1&gt;

{% for story in story_list %}
&lt;h2&gt;
  &lt;a href=&quot;{{ story.get_absolute_url }}&quot;&gt;
    {{ story.headline|upper }}
  &lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;{{ story.tease|truncatewords:&quot;100&quot; }}&lt;/p&gt;
{% endfor %}
{% endblock %}
</pre>
<div class="admonition- admonition">
<p class="first admonition-title">哲学</p>
<p class="last">为什么使用基于文本的模板系统而不是基于 XML (类似 Zope 的 TAL)? 我们希望 Django 的模板语言能比那些 XML/HTML 模板更可用.在 World Online, 我们使用它处理 e-mails, JavaScript 和 CSV. 你能使用这种模板语言生成任何基于文本的格式. 哦,还有一个理由,那就是我们认为除非一个人有受虐趋向，否则谁也不愿意手工编辑 xml。</p>
</div>
</div>
<div class="section">
<h1><a id="variables" name="variables">Variables</a></h1>
<p>变量的形式: <tt class="docutils literal"><span class="pre">{{</span> <span class="pre">variable</span> <span class="pre">}}</span></tt>. 当模板引擎遇到一个变量时,就会对变量求值,并在变量所在的位置用变量的值取代变量名,然后输出.</p>
<p>使用句点 (<tt class="docutils literal"><span class="pre">.</span></tt>) 可以访问变量的属性.</p>
<div class="admonition- admonition">
<p class="first admonition-title">幕后</p>
<p>技术上,当模板系统遇到 句点, 它会按顺序尝试进依次查询:</p>
<blockquote class="last">
<ul class="simple">
<li>Dictionary lookup</li>
<li>Attribute lookup</li>
<li>Method call</li>
<li>List-index lookup</li>
</ul>
</blockquote>
</div>
<p>在上面的例子中, <tt class="docutils literal"><span class="pre">{{</span> <span class="pre">section.title</span> <span class="pre">}}</span></tt> 会被 <tt class="docutils literal"><span class="pre">section</span></tt> 对象的 <tt class="docutils literal"><span class="pre">title</span></tt> 属性替换.</p>
<p>如果你用到的一个变量不存在,模板系统会插入一个值:<tt class="docutils literal"><span class="pre">TEMPLATE_STRING_IF_INVALID</span></tt> ,这个值在 settings 中定义, 默认设置是一个空的字符串.</p>
<p>参见下面的 <a class="reference" href="#id4">使用内建参考</a> , 这会帮助你发现给定模板中有哪些变量可用.</p>
<p>你可以使用 <strong>过滤器</strong> 来修改变量的显示.</p>
</div>
<div class="section">
<h1><a id="id1" name="id1">过滤器</a></h1>
<p>通过使用 <strong>过滤器</strong> ，可以定制变量的显示格式。</p>
<p>过滤器的形式: <tt class="docutils literal"><span class="pre">{{</span> <span class="pre">name|lower</span> <span class="pre">}}</span></tt>. 这将显示 <tt class="docutils literal"><span class="pre">{{</span> <span class="pre">name</span> <span class="pre">}}</span></tt> 变量通过 <tt class="docutils literal"><span class="pre">lower</span></tt> 过滤后的值. 它将文本转换为小写. 使用管道符号 (<tt class="docutils literal"><span class="pre">|</span></tt>) 应用一个过滤器.</p>
<p>过滤器可以 &quot;链接&quot;. 一个过滤器的输入作为下一个过滤器的输入: <tt class="docutils literal"><span class="pre">{{</span> <span class="pre">text|escape|linebreaks</span> <span class="pre">}}</span></tt> 是一个常用过滤器组合,用于将文本内容转义然后将换行转换成 <tt class="docutils literal"><span class="pre">&lt;p&gt;</span></tt> 标签.</p>
<p>有些过滤器能接受参数. 一个带有参数的过滤器看起来这样: <tt class="docutils literal"><span class="pre">{{</span> <span class="pre">bio|truncatewords:&quot;30&quot;</span> <span class="pre">}}</span></tt>. 它用来显示 <tt class="docutils literal"><span class="pre">bio</span></tt> 变量的前 30 个. 过滤器参数总是带有比引号. 下文中的 <a class="reference" href="#id9">内建过滤器参考</a> 描述了所有的内建过滤器.</p>
</div>
<div class="section">
<h1><a id="id2" name="id2">标签</a></h1>
<p>标签看起来这样: <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">标签</span> <span class="pre">%}</span></tt>. 标签比起变量来复杂的多: 它负责在输出中创建一些文本,执行循环或逻辑分支, 装入额外信息以供后面的模板变量使用等等.</p>
<p>有些标签要求有开始标记和结束标记 (也就是 <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">tag</span> <span class="pre">%}</span> <span class="pre">...</span> <span class="pre">标签内容</span> <span class="pre">...</span> <span class="pre">{%</span> <span class="pre">endtag</span> <span class="pre">%}</span></tt>). 下文中的 <a class="reference" href="#id8">内建标签参考</a> 描述了所有的内建标签.你也可以创建你自己的标签, 如果你会写 Python 代码的话.</p>
</div>
<div class="section">
<h1><a id="id3" name="id3">模板继承</a></h1>
<p>Django 模板引擎最强大的 &#8212; 也是最复杂的 &#8212; 部分是模板继承. 模板继承允许你建立一个基本的 &quot;骨架&quot; 模板, 它包含你所有最常用的站点元素并定义了一些可以被子模板覆盖的 <strong>块</strong> .</p>
<p>通过下面的例子你很容易理解模板继承:</p>
<pre class="literal-block">

&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
    &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot; lang=&quot;en&quot;&gt;
&lt;head&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot; /&gt;
    &lt;title&gt;{% block title %}My amazing site{% endblock %}&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
    &lt;div id=&quot;sidebar&quot;&gt;
        {% block sidebar %}
        &lt;ul&gt;
            &lt;li&gt;&lt;a href=&quot;/&quot;&gt;Home&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href=&quot;/blog/&quot;&gt;Blog&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
        {% endblock %}
    &lt;/div&gt;

    &lt;div id=&quot;content&quot;&gt;
        {% block content %}{% endblock %}
    &lt;/div&gt;
&lt;/body&gt;
</pre>
<p>我们称它为 <tt class="docutils literal"><span class="pre">base.html</span></tt>, 定义了一些简单的 HTML 骨架文档, 你可以把它用到一些简单两列的网页上. &quot;子&quot; 模板的任务就是用内容填写这些空白的内容块.</p>
<p>在这个例子里, <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">block</span> <span class="pre">%}</span></tt> 标签定义了三个子模板要填写的 block . 所有的 <tt class="docutils literal"><span class="pre">block</span></tt> 标签告诉模板引擎,模板的这些部分可以被子模板覆盖.</p>
<p>一个子模板类似下面这样:</p>
<pre class="literal-block">

{% extends &quot;base.html&quot; %}

{% block title %}My amazing blog{% endblock %}

{% block content %}
{% for entry in blog_entries %}
    &lt;h2&gt;{{ entry.title }}&lt;/h2&gt;
    &lt;p&gt;{{ entry.body }}&lt;/p&gt;
{% endfor %}
{% endblock %}
</pre>
<p>这里的 <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">extends</span> <span class="pre">%}</span></tt> 标签是最关键的. 它告诉模板引擎这个模板 &quot;扩展&quot; 了另一个模板. 当模板系统要应用该模板时,首先它会去寻找父模板&#8211;在这里是 &quot;base.html&quot; .</p>
<p>模板引擎会注意到在 <tt class="docutils literal"><span class="pre">base.html</span></tt> 里有三个 block 并用子模板的相关内容替换这些 block. 用 <tt class="docutils literal"><span class="pre">blog_entries</span></tt> 里的值填写父模板之后, 最后的输出可能看起来象这样:</p>
<pre class="literal-block">

&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
    &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot; lang=&quot;en&quot;&gt;
&lt;head&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot; /&gt;
    &lt;title&gt;My amazing blog&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
    &lt;div id=&quot;sidebar&quot;&gt;
        &lt;ul&gt;
            &lt;li&gt;&lt;a href=&quot;/&quot;&gt;Home&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href=&quot;/blog/&quot;&gt;Blog&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
    &lt;/div&gt;

    &lt;div id=&quot;content&quot;&gt;
        &lt;h2&gt;Entry one&lt;/h2&gt;
        &lt;p&gt;This is my first entry.&lt;/p&gt;

        &lt;h2&gt;Entry two&lt;/h2&gt;
        &lt;p&gt;This is my second entry.&lt;/p&gt;
    &lt;/div&gt;
&lt;/body&gt;
</pre>
<p>注意由于子模板并未定义 <tt class="docutils literal"><span class="pre">sidebar</span></tt> block, 父模板中的值就被保留.</p>
<p>对模板的继承层数,Django未做任何限制. 常用的一种模板继承方法是如下的三层:</p>
<pre class="literal-block">

* 创建一个 ``base.html`` 模板，用它表现站点主要的外观。

* 为站点的每个 section 创建一个 ``base_SECTIONNAME.html`` 模板。比如 ``base_news.html``,``base_sport.html``等等， 这些模板扩充了 ``base.html`` 并包括 section 特有的样式和设计。

* 为每种类型的页面创建一个独立的模板，比如一篇新闻稿或者一个博客，这些模板扩展了相应的 section 模板。

这种方式能够最大程度的重用代码并能很容易的扩充内容及共享内容区块，比如 section-范围的导航。
</pre>
<p>下面是使用模板继承的一些小技巧:</p>
<pre class="literal-block">

* 如果你在模板中使用了 ``{% extends %}`` ,那么它必须是这个模板中的第一个模板 tag ，否则它就不工作。

* 在父模板中 ``{% block %}`` 标签虽然不是越多越好,总得来说多比少好. 记住,子模板不需要定义所有的 parent block, 因此你可以先定义一系列 blocks 并填入合理的默认值, 然后定义那些你以后才需要的 block. It's better to have more hooks than fewer hooks.

* 如果发现在一堆模板文件中重复定义相同的内容, 就意味着需要将这些内容放到父模板的一个 ``{% block %}`` 中去.

* 如果你需要在子模板中引用父模板中的 block 的内容,使用 ``{{ block.super }}`` 变量. 这在你希望在父模板的内容之后添加一些内容时会很有用.(你不必完全覆盖父模板的内容.)
</pre>
<p>最后, 提醒你不能在一个模板文件中定义多个相同名字的 <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">block</span> <span class="pre">%}</span></tt> 标签.</p>
</div>
<div class="section">
<h1><a id="id4" name="id4">使用内建参考</a></h1>
<p>Django 自带的 admin site 内建一个当前站点的所有模板标签及过滤器的参考. 要查阅这个参考, 进入 admin 站点，然后点击页面右上角的 &quot;Documentation&quot; 链接(如果你的语言选择的是中文,你会看到一个 &quot;文档&quot; 链接)..</p>
<p>这个参考分为四大部分:tags, filters, models, 和 views.</p>
<p><strong>tags</strong> 和 <strong>filters</strong> 部分描述了所有的内建标签(事实上, 下文中的标签和过滤器 参考直接来自那些页面)和所有自定义标签或过滤器 库(如果有的话).</p>
<p><strong>views</strong> 页是最有价值的.你站点中的每个 URL 都有一个入口在这儿, 点击这个 URL 你会看到:</p>
<blockquote>
<ul class="simple">
<li>生成该页面的 view 函数的名字</li>
<li>该 view 功能的一个简短的描述.</li>
<li>该 view 的 <strong>context</strong>, 或者该 view 对应模板中的可用变量列表</li>
<li>模板的名字,或该模板使用到的模板名字</li>
</ul>
</blockquote>
<p>每个 view 文档页还有一个 bookmarklet , 使用它你可以任意页跳回到这个 view 页.</p>
<p>由于 Django 站点通常会用到数据库对象, 文档页的 <strong>models</strong> 小节描述了系统中每个对象的类型及那个对象的所有可用字段.</p>
<p>总得来说, 文档页会告诉你给定模板的每个标签, 每个过滤器,每个变量和对象的细节信息.</p>
</div>
<div class="section">
<h1><a id="id5" name="id5">自定义标签及过滤器库</a></h1>
<p>某些应用提供自定义标签和过滤器库. 要在一个模板中访问它们, 使用 <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">load</span> <span class="pre">%}</span></tt> 标签:</p>
<pre class="literal-block">

{% load comments %}

{% comment_form for blogs.entries entry.id with is_public yes %}
</pre>
<p>在上面这个例子里, <tt class="docutils literal"><span class="pre">load</span></tt> 标签载入 <tt class="docutils literal"><span class="pre">comments</span></tt> 标签库, 之后 <tt class="docutils literal"><span class="pre">comment_form</span></tt> 标签才能使用. 参考你的 admin 界面的文档部分你会发现一个自定义库的列表. <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">load</span> <span class="pre">%}</span></tt> 标签可接受空隔分隔的多个库的名字作为参数. 比如:</p>
<pre class="literal-block">

{% load comments i18n %}
</pre>
<div class="section">
<h2><a id="id6" name="id6">自定义库及模板继承</a></h2>
<p>当你载入一个自定义标签或过滤器库, 只有当前模板可以使用这些标签/过滤器 &#8212; 继承链中不论是父模板还是子模板都不能使用使用这些标签和过滤器.</p>
<p>举例来说, 如果一个模板 <tt class="docutils literal"><span class="pre">foo.html</span></tt> 内有 <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">load</span> <span class="pre">comments</span> <span class="pre">%}</span></tt> 指令, 一个子模板(也就是一个模板内有 <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">extends</span> <span class="pre">&quot;foo.html&quot;</span> <span class="pre">%}</span></tt> 指令将 <em>不能</em> 访问 comments 模板标签和过滤器. 子模板必须自己负责 <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">load</span> <span class="pre">comments</span> <span class="pre">%}</span></tt> 才可以使用这个库.</p>
<p>这是为了模板逻辑的清晰性和可维护性有意而为的一个特性.</p>
</div>
</div>
<div class="section">
<h1><a id="id7" name="id7">内建标签和过滤器参考</a></h1>
<p>下面的标签和过滤器参考就是为那些没有 admin 站点的可用的人准备的.由于 Django 是高度可定制的,你的 admin 里的关于标签和过滤器的参考可以认为是最可信的.</p>
<div class="section">
<h2><a id="id8" name="id8">内建标签参考</a></h2>
<div class="section">
<h3><a id="block" name="block">block</a></h3>
<p>定义一个能被子模板覆盖的 块. 参阅 <a class="reference" href="#id3">模板继承</a> 了解更多信息</p>
</div>
<div class="section">
<h3><a id="comment" name="comment">comment</a></h3>
<p>注释.模板引擎会忽略掉 <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">comment</span> <span class="pre">%}</span></tt> 和 <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">endcomment</span> <span class="pre">%}</span></tt> 之间的所有内容.</p>
</div>
<div class="section">
<h3><a id="cycle" name="cycle">cycle</a></h3>
<p>在循环时轮流使用给定的字符串列表中的值.</p>
<p>在一个循环中, 在循环过程中的每次循环里轮流使用给定的字符串列表元素:</p>
<pre class="literal-block">

{% for o in some_list %}
    &lt;tr class=&quot;{% cycle row1,row2 %}&quot;&gt;
        ...
    &lt;/tr&gt;
{% endfor %}
</pre>
<p>在循环之外, 在你第一次调用它时给这些字符串值定义一个不重复的名字,然后在循环中使用这个名字:</p>
<pre class="literal-block">

&lt;tr class=&quot;{% cycle row1,row2,row3 as rowcolors %}&quot;&gt;...&lt;/tr&gt;
&lt;tr class=&quot;{% cycle rowcolors %}&quot;&gt;...&lt;/tr&gt;
&lt;tr class=&quot;{% cycle rowcolors %}&quot;&gt;...&lt;/tr&gt;
</pre>
<p>你可以使用任意数量的逗号分隔的值.只有一点请你注意,不要在值与值之间放任何空隔&#8211;仅仅只有一个逗号即可.</p>
</div>
<div class="section">
<h3><a id="debug" name="debug">debug</a></h3>
<p>输出完整的调试信息,包括当前的上下文及导入的模块信息.</p>
</div>
<div class="section">
<h3><a id="extends" name="extends">extends</a></h3>
<p>当前模板 扩展 父模板的一个信号(标记).</p>
<p>这个标签有两种使用方式: <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">extends</span> <span class="pre">&quot;base.html&quot;</span> <span class="pre">%}</span></tt> (带双引号) 使用 &quot;base&quot; 作为要扩展的父模板的名字.或者 <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">extends</span> <span class="pre">variable</span> <span class="pre">%}</span></tt> 使用 <tt class="docutils literal"><span class="pre">variable</span></tt> 的值作为要扩展的父模板的名字.</p>
<p>参阅 <a class="reference" href="#id3">模板继承</a> 以了解更多信息.</p>
</div>
<div class="section">
<h3><a id="filter" name="filter">filter</a></h3>
<p>用来过滤变量的值.</p>
<p>允许多级过滤, 并且他们可以带有参数运行 &#8212; just like in variable syntax.</p>
<p>示例:</p>
<pre class="literal-block">

{% filter escape|lower %}
    文本将被 HTML-转义, 并且全部转化为小写
{% end过滤器 %}
</pre>
</div>
<div class="section">
<h3><a id="firstof" name="firstof">firstof</a></h3>
<p>输出传递给它的第一个不是 False 的变量值. 如果所有的变量都是 False 那就不输出任何东西.</p>
<p>示例:</p>
<pre class="literal-block">

{% firstof var1 var2 var3 %}
</pre>
<p>它等价于:</p>
<pre class="literal-block">

{% if var1 %}
    {{ var1 }}
{% else %}{% if var2 %}
    {{ var2 }}
{% else %}{% if var3 %}
    {{ var3 }}
{% endif %}{% endif %}{% endif %}
</pre>
</div>
<div class="section">
<h3><a id="for" name="for">for</a></h3>
<p>循环. 比如要显示一个 <tt class="docutils literal"><span class="pre">athlete_list</span></tt> 中的全部运动员:</p>
<pre class="literal-block">

&lt;ul&gt;
{% for athlete in athlete_list %}
    &lt;li&gt;{{ athlete.name }}&lt;/li&gt;
{% endfor %}
&lt;/ul&gt;
</pre>
<p>通过使用 <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">for</span> <span class="pre">obj</span> <span class="pre">in</span> <span class="pre">list</span> <span class="pre">reversed</span> <span class="pre">%}</span></tt> 你也可以实现反序循环.</p>
<p>在循环过程中 for 循环会设置以下的一系列变量:</p>
<blockquote>
<table class="docutils" border="1">
<colgroup>
<col width="35%" />
<col width="65%" /></colgroup>
<thead valign="bottom">
<tr>
<th class="head">Variable</th>
<th class="head">Description</th>
</tr>
</thead>
<tbody valign="top">
<tr>
<td><tt class="docutils literal"><span class="pre">forloop.counter</span></tt></td>
<td>当前循环次数 (1-indexed)</td>
</tr>
<tr>
<td><tt class="docutils literal"><span class="pre">forloop.counter0</span></tt></td>
<td>当前循环次数 (0-indexed)</td>
</tr>
<tr>
<td><tt class="docutils literal"><span class="pre">forloop.revcounter</span></tt></td>
<td>倒序循环时当前循环次数(1-indexed)</td>
</tr>
<tr>
<td><tt class="docutils literal"><span class="pre">forloop.revcounter0</span></tt></td>
<td>倒序循环时当前循环次数(0-indexed)</td>
</tr>
<tr>
<td><tt class="docutils literal"><span class="pre">forloop.first</span></tt></td>
<td>如果当前循环是循环过程的第一次则为True</td>
</tr>
<tr>
<td><tt class="docutils literal"><span class="pre">forloop.last</span></tt></td>
<td>如果当前循环是循环过程的最后一次则为True</td>
</tr>
<tr>
<td><tt class="docutils literal"><span class="pre">forloop.parentloop</span></tt></td>
<td>对嵌套循环, 当前循环之上的循环</td>
</tr>
</tbody>
</table>
</blockquote>
</div>
<div class="section">
<h3><a id="if" name="if">if</a></h3>
<p><tt class="docutils literal"><span class="pre">{%</span> <span class="pre">if</span> <span class="pre">%}</span></tt> 标签对一个变量求值, 若这个变量为 &quot;true&quot; , 就输出 <tt class="docutils literal"><span class="pre">if</span></tt> 内容块:</p>
<pre class="literal-block">

{% if athlete_list %}
    Number of athletes: {{ athlete_list|length }}
{% else %}
    No athletes.
{% endif %}
</pre>
<p>在上例中, 如果 <tt class="docutils literal"><span class="pre">athlete_list</span></tt> 非空, 运动员人数就会通过 <tt class="docutils literal"><span class="pre">{{</span> <span class="pre">athlete_list|length</span> <span class="pre">}}</span></tt> 变量显示出来.</p>
<p>就象你刚刚看到的, <tt class="docutils literal"><span class="pre">if</span></tt> 标签可以带一个 <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">else</span> <span class="pre">%}</span></tt> 子句,用来当 <tt class="docutils literal"><span class="pre">if</span></tt> 测试失败后输出相应的内容块.</p>
<p><tt class="docutils literal"><span class="pre">if``标签可以使用</span> <span class="pre">``and</span></tt>,&#8220;or&#8220; 或 <tt class="docutils literal"><span class="pre">not</span></tt> 来测试一系列变量或否定一个给定的变量:</p>
<pre class="literal-block">

{% if athlete_list and coach_list %}
    Both athletes and coaches are available.
{% endif %}

{% if not athlete_list %}
    There are no athletes.
{% endif %}

{% if athlete_list or coach_list %}
    There are some athletes or some coaches.
{% endif %}

{% if not athlete_list or coach_list %}
    There are no athletes or there are some coaches (OK, so
    writing English translations of boolean logic sounds
    stupid; it's not our fault).
{% endif %}

{% if athlete_list and not coach_list %}
    There are some athletes and absolutely no coaches.
{% endif %}
</pre>
<p>为避免造成歧义, <tt class="docutils literal"><span class="pre">if``标签不允许在一个</span> <span class="pre">tag</span> <span class="pre">中同时有</span> <span class="pre">``and</span></tt> 和 <tt class="docutils literal"><span class="pre">or</span></tt> 逻辑; 举个例子，下面这个语句不能工作:</p>
<pre class="literal-block">

{% if athlete_list and coach_list or other_list %}
</pre>
<p>如果确实需要组合条件，可以使用嵌套的 <tt class="docutils literal"><span class="pre">if</span></tt> 实现相同的功能:</p>
<pre class="literal-block">

{% if athlete_list %}
    {% if coach_list or other_list %}
         We have athletes and , either coaches or others.
    {% endif %}
{% endif %}
</pre>
</div>
<div class="section">
<h3><a id="ifchanged" name="ifchanged">ifchanged</a></h3>
<p>检查一个变量自上次循环之后是否发生了改变.(我的理解:主要用于过滤掉重复的值)</p>
<p>&#8216;ifchanged&#8217; block标签用于循环中. 它根据自身上次的状态检查自己值, 只有值发生变化时才显示这个值:</p>
<pre class="literal-block">

&lt;h1&gt;Archive for {{ year }}&lt;/h1&gt;

{% for day in days %}
{% ifchanged %}&lt;h3&gt;{{ day|date:&quot;F&quot; }}&lt;/h3&gt;{% endifchanged %}
&lt;a href=&quot;{{ day|date:&quot;M/d&quot;|lower }}/&quot;&gt;{{ day|date:&quot;j&quot; }}&lt;/a&gt;
{% endfor %}
</pre>
</div>
<div class="section">
<h3><a id="ifequal" name="ifequal">ifequal</a></h3>
<p>若两个参数相等,输出一个内容块.</p>
<p>例子:</p>
<pre class="literal-block">

{% ifequal user.id comment.user_id %}
    ...
{% endifequal %}
</pre>
<p>如同 <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">if</span> <span class="pre">%}</span></tt> tag, 它也支持一个可选的 <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">else</span> <span class="pre">%}</span></tt> 子句.</p>
<p>参数可以是变量,也可以是字符串字面值, 也就是说下面这样也是合法的:</p>
<pre class="literal-block">

{% ifequal user.username &quot;adrian&quot; %}
    ...
{% endifequal %}
</pre>
</div>
<div class="section">
<h3><a id="ifnotequal" name="ifnotequal">ifnotequal</a></h3>
<p>类似 <tt class="docutils literal"><span class="pre">ifequal</span></tt>, 只是它用来测试两个参数是否不等.</p>
</div>
<div class="section">
<h3><a id="include" name="include">include</a></h3>
<p>载入一个模板并根据当前上下文渲染它.用于在一个模板中包含其它模板.</p>
<p>模板名字可以是一个变量,也可以是一个字符串(带引号的字符串,无所谓单引号还是双引号).</p>
<p>下面这个例子包含了 <tt class="docutils literal"><span class="pre">&quot;foo/bar.html&quot;</span></tt> 模板的内容:</p>
<pre class="literal-block">

{% include &quot;foo/bar.html&quot; %}
</pre>
<p>下面这个例子包含了另一个模板(该模板的名字为变量 <tt class="docutils literal"><span class="pre">template_name</span></tt> 的值)的内容:</p>
<pre class="literal-block">

{% include template_name %}
</pre>
<p>被包含的模板使用包含它的模板的上下文(也就是环境)进行渲染(求值),下面这个例子输出 <tt class="docutils literal"><span class="pre">&quot;Hello,</span> <span class="pre">John&quot;</span></tt>:</p>
<blockquote>
<ul>
<li>
<p class="first">Context: variable <tt class="docutils literal"><span class="pre">person</span></tt> is set to <tt class="docutils literal"><span class="pre">&quot;john&quot;</span></tt>.</p>
</li>
<li>
<p class="first">Template:</p>
<pre class="literal-block">

{% include &quot;name_snippet.html&quot; %}
</pre>
</li>
<li>
<p class="first">The <tt class="docutils literal"><span class="pre">name_snippet.html</span></tt> template:</p>
<pre class="literal-block">

Hello, {{ person }}
</pre>
</li>
</ul>
</blockquote>
<p>参阅: <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">ssi</span> <span class="pre">%}</span></tt>.</p>
</div>
<div class="section">
<h3><a id="load" name="load">load</a></h3>
<p>装入一个自定义模板标签集.</p>
<p>参阅 <a class="reference" href="#id5">自定义标签及过滤器库</a> 以了解更多信息.</p>
</div>
<div class="section">
<h3><a id="now" name="now">now</a></h3>
<p>显示当前日期, 根据给定的字符串决定输出格式.</p>
<p>使用和 PHP 的 <tt class="docutils literal"><span class="pre">date()</span></tt> 函数一样的格式码 (<a class="reference" href="http://php.net/date">http://php.net/date</a>) 并做了一些扩展</p>
<p>可用的格式字符串:</p>
<blockquote>
<table class="docutils" border="1">
<colgroup>
<col width="12%" />
<col width="31%" />
<col width="57%" /></colgroup>
<thead valign="bottom">
<tr>
<th class="head">格式字符</th>
<th class="head">描述</th>
<th class="head">输出示例</th>
</tr>
</thead>
<tbody valign="top">
<tr>
<td>a</td>
<td><tt class="docutils literal"><span class="pre">'a.m.'</span></tt> 或 <tt class="docutils literal"><span class="pre">'p.m.'</span></tt> (注意,它与PHP 的输出略有不同.它包括了句点(django扩展).</td>
<td><tt class="docutils literal"><span class="pre">'a.m.'</span></tt></td>
</tr>
<tr>
<td>A</td>
<td><tt class="docutils literal"><span class="pre">'AM'</span></tt> 或 <tt class="docutils literal"><span class="pre">'PM'</span></tt>.</td>
<td><tt class="docutils literal"><span class="pre">'AM'</span></tt></td>
</tr>
<tr>
<td>B</td>
<td>未实现.</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>d</td>
<td>每月第几天, 带前导零</td>
<td><tt class="docutils literal"><span class="pre">'01'</span></tt> to <tt class="docutils literal"><span class="pre">'31'</span></tt></td>
</tr>
<tr>
<td>D</td>
<td>每周第几天,3字母的字符串.</td>
<td><tt class="docutils literal"><span class="pre">'Fri'</span></tt></td>
</tr>
<tr>
<td>f</td>
<td>时间, 12-小时制的小时和分钟数, 如果分钟数为零,则不显示.(django 扩展).</td>
<td><tt class="docutils literal"><span class="pre">'1'</span></tt>, <tt class="docutils literal"><span class="pre">'1:30'</span></tt></td>
</tr>
<tr>
<td>F</td>
<td>月份, 长文本格式.</td>
<td><tt class="docutils literal"><span class="pre">'January'</span></tt></td>
</tr>
<tr>
<td>g</td>
<td>小时, 12-小时制,没有前导零</td>
<td><tt class="docutils literal"><span class="pre">'1'</span></tt> to <tt class="docutils literal"><span class="pre">'12'</span></tt></td>
</tr>
<tr>
<td>G</td>
<td>小时, 24-小时制,没有前导零</td>
<td><tt class="docutils literal"><span class="pre">'0'</span></tt> to <tt class="docutils literal"><span class="pre">'23'</span></tt></td>
</tr>
<tr>
<td>h</td>
<td>小时, 12-小时制,有前导零</td>
<td><tt class="docutils literal"><span class="pre">'01'</span></tt> to <tt class="docutils literal"><span class="pre">'12'</span></tt></td>
</tr>
<tr>
<td>H</td>
<td>小时, 24-小时制,有前导零</td>
<td><tt class="docutils literal"><span class="pre">'00'</span></tt> to <tt class="docutils literal"><span class="pre">'23'</span></tt></td>
</tr>
<tr>
<td>i</td>
<td>分钟.</td>
<td><tt class="docutils literal"><span class="pre">'00'</span></tt> to <tt class="docutils literal"><span class="pre">'59'</span></tt></td>
</tr>
<tr>
<td>I</td>
<td>未实现</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>j</td>
<td>每月第几天, 无前导零</td>
<td><tt class="docutils literal"><span class="pre">'1'</span></tt> to <tt class="docutils literal"><span class="pre">'31'</span></tt></td>
</tr>
<tr>
<td>l</td>
<td>每周第几天,长文本格式.</td>
<td><tt class="docutils literal"><span class="pre">'Friday'</span></tt></td>
</tr>
<tr>
<td>L</td>
<td>是否闰年.</td>
<td><tt class="docutils literal"><span class="pre">True</span></tt> or <tt class="docutils literal"><span class="pre">False</span></tt></td>
</tr>
<tr>
<td>m</td>
<td>数字表示的月份,有前导零.</td>
<td><tt class="docutils literal"><span class="pre">'01'</span></tt> to <tt class="docutils literal"><span class="pre">'12'</span></tt></td>
</tr>
<tr>
<td>M</td>
<td>月份,3字母短文本格式.</td>
<td><tt class="docutils literal"><span class="pre">'Jan'</span></tt></td>
</tr>
<tr>
<td>n</td>
<td>数字表示的月份,无前导零</td>
<td><tt class="docutils literal"><span class="pre">'1'</span></tt> to <tt class="docutils literal"><span class="pre">'12'</span></tt></td>
</tr>
<tr>
<td>N</td>
<td>出版风格的月份缩写(django 扩展)</td>
<td><tt class="docutils literal"><span class="pre">'Jan.'</span></tt>, <tt class="docutils literal"><span class="pre">'Feb.'</span></tt>, <tt class="docutils literal"><span class="pre">'March'</span></tt>, <tt class="docutils literal"><span class="pre">'May'</span></tt></td>
</tr>
<tr>
<td>O</td>
<td>与格林威治的时间差(以小时计)</td>
<td><tt class="docutils literal"><span class="pre">'+0200'</span></tt></td>
</tr>
<tr>
<td>P</td>
<td>12小时制的小时分钟及&#8217;a.m.&#8217;/'p.m.&#8217; 分钟数若为零则不显示. 用字符串表示特殊的时间点, 如 &#8216;midnight&#8217; 和 &#8216;noon&#8217; (django扩展)</td>
<td><tt class="docutils literal"><span class="pre">'1</span> <span class="pre">a.m.'</span></tt>, <tt class="docutils literal"><span class="pre">'1:30</span> <span class="pre">p.m.'</span></tt>, <tt class="docutils literal"><span class="pre">'midnight'</span></tt>, <tt class="docutils literal"><span class="pre">'noon'</span></tt>, <tt class="docutils literal"><span class="pre">'12:30</span> <span class="pre">p.m.'</span></tt></td>
</tr>
<tr>
<td>r</td>
<td>RFC 822 格式的日期 .</td>
<td><tt class="docutils literal"><span class="pre">'Thu,</span> <span class="pre">21</span> <span class="pre">Dec</span> <span class="pre">2000</span> <span class="pre">16:01:07</span> <span class="pre">+0200'</span></tt></td>
</tr>
<tr>
<td>s</td>
<td>秒数, 带有前导零的数字表示</td>
<td><tt class="docutils literal"><span class="pre">'00'</span></tt> to <tt class="docutils literal"><span class="pre">'59'</span></tt></td>
</tr>
<tr>
<td>S</td>
<td>英语序数后缀,用于一个月的第几天,2个字符</td>
<td><tt class="docutils literal"><span class="pre">'st'</span></tt>, <tt class="docutils literal"><span class="pre">'nd'</span></tt>, <tt class="docutils literal"><span class="pre">'rd'</span></tt> or <tt class="docutils literal"><span class="pre">'th'</span></tt></td>
</tr>
<tr>
<td>t</td>
<td>给定月共有多少天.</td>
<td><tt class="docutils literal"><span class="pre">28</span></tt> to <tt class="docutils literal"><span class="pre">31</span></tt></td>
</tr>
<tr>
<td>T</td>
<td>本机时区.</td>
<td><tt class="docutils literal"><span class="pre">'EST'</span></tt>, <tt class="docutils literal"><span class="pre">'MDT'</span></tt></td>
</tr>
<tr>
<td>U</td>
<td>未实现</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>w</td>
<td>一周中的第几天,没有前导零的数字</td>
<td><tt class="docutils literal"><span class="pre">'0'</span></tt> (Sunday) to <tt class="docutils literal"><span class="pre">'6'</span></tt> (Saturday)</td>
</tr>
<tr>
<td>W</td>
<td>ISO-8601 一年的第多少星期数, 一周从星期一开始</td>
<td><tt class="docutils literal"><span class="pre">1</span></tt>, <tt class="docutils literal"><span class="pre">23</span></tt></td>
</tr>
<tr>
<td>y</td>
<td>Year, 2 位数字表示</td>
<td><tt class="docutils literal"><span class="pre">'99'</span></tt></td>
</tr>
<tr>
<td>Y</td>
<td>Year, 4 位数字表示</td>
<td><tt class="docutils literal"><span class="pre">'1999'</span></tt></td>
</tr>
<tr>
<td>z</td>
<td>一年中的第几天 .</td>
<td><tt class="docutils literal"><span class="pre">0</span></tt> to <tt class="docutils literal"><span class="pre">365</span></tt></td>
</tr>
<tr>
<td>Z</td>
<td>以秒计的时区偏移量. 这个偏移量对UTC西部时区总是负数,而对UTC东部时区则总是正数</td>
<td><tt class="docutils literal"><span class="pre">-43200</span></tt> to <tt class="docutils literal"><span class="pre">43200</span></tt></td>
</tr>
</tbody>
</table>
</blockquote>
<p>例子:</p>
<pre class="literal-block">

It is {% now &quot;jS F Y H:i&quot; %}
</pre>
<p>注意你可以使用反斜线转义一个格式字符串中的敏感字符.(如果你想使用其原始值的话).在下面这个例子里, &quot;f&quot; 被用反斜线转义, 因为 &quot;f&quot; 本身是一个用于显示时间的格式字符. &quot;o&quot; 不需要被转义,因为它不是一个格式字符.:</p>
<pre class="literal-block">

It is the {% now &quot;jS o\f F&quot; %}
</pre>
<p>(显示 &quot;It is the 4th of September&quot; %}</p>
</div>
<div class="section">
<h3><a id="regroup" name="regroup">regroup</a></h3>
<p>Regroup a list of alike objects by a common attribute.</p>
<p>要搞懂这个复杂的标签, 最好还是用一个例子来说明(一幅图胜过千句话): 有一个 <tt class="docutils literal"><span class="pre">people</span></tt> 对象,它是一个 <tt class="docutils literal"><span class="pre">Person</span></tt> 对象(拥有 <tt class="docutils literal"><span class="pre">first_name</span></tt>, <tt class="docutils literal"><span class="pre">last_name</span></tt> 及 <tt class="docutils literal"><span class="pre">gender</span></tt> 属性)的列表. 你想显示一个象下面这样的列表:</p>
<blockquote>
<ul>
<li>
<dl class="first docutils">
<dt>Male: </dt>
<dd>
<ul class="first last simple">
<li>George Bush</li>
<li>Bill Clinton</li>
</ul>
</dd>
</dl>
</li>
<li>
<dl class="first docutils">
<dt>Female: </dt>
<dd>
<ul class="first last simple">
<li>Margaret Thatcher</li>
<li>Condoleezza Rice</li>
</ul>
</dd>
</dl>
</li>
<li>
<dl class="first docutils">
<dt>Unknown: </dt>
<dd>
<ul class="first last simple">
<li>Pat Smith</li>
</ul>
</dd>
</dl>
</li>
</ul>
</blockquote>
<p>下面的模板代码片断可以完成这个看上去复杂的任务:</p>
<pre class="literal-block">

{% regroup people by gender as grouped %}
&lt;ul&gt;
{% for group in grouped %}
    &lt;li&gt;{{ group.grouper }}
    &lt;ul&gt;
        {% for item in group.list %}
        &lt;li&gt;{{ item }}&lt;/li&gt;
        {% endfor %}
    &lt;/ul&gt;
{% endfor %}
&lt;/ul&gt;
</pre>
<p>如同你看到的, <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">regroup</span> <span class="pre">%}</span></tt> 生成一个变量包含一个对象的列表. 列表中的每个对象都拥有 <tt class="docutils literal"><span class="pre">grouper</span></tt> 和 <tt class="docutils literal"><span class="pre">list</span></tt> 属性. <tt class="docutils literal"><span class="pre">grouper</span></tt> 装有分组的条目; <tt class="docutils literal"><span class="pre">list</span></tt> 包含一系列拥有共同 <tt class="docutils literal"><span class="pre">grouper</span></tt> 属性的对象. 在这个例子里, <tt class="docutils literal"><span class="pre">grouper</span></tt> 可能是 <tt class="docutils literal"><span class="pre">Male</span></tt>, <tt class="docutils literal"><span class="pre">Female</span></tt> 和 <tt class="docutils literal"><span class="pre">Unknown</span></tt>, 而 <tt class="docutils literal"><span class="pre">list</span></tt> 则是属于这几种性别的人的列表.</p>
<p>注意当这个被分组的列表没有按你要分组的键排序时, <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">regroup</span> <span class="pre">%}</span></tt> 将不能工作! 这就是说你的 people 列表如果没有按 <tt class="docutils literal"><span class="pre">gender</span></tt> 排序, 你就必须得保证在使用它之前先将它排好序,也就是:</p>
<pre class="literal-block">

{% regroup people|dictsort:&quot;gender&quot; by gender as grouped %}
</pre>
</div>
<div class="section">
<h3><a id="spaceless" name="spaceless">spaceless</a></h3>
<p>将HTML标签之间的空白格式化为一个空格. 空白包括空格,换行,制表符.</p>
<p>示例:</p>
<pre class="literal-block">

{% spaceless %}
    &lt;p&gt;
        &lt;a href=&quot;foo/&quot;&gt;Foo&lt;/a&gt;
    &lt;/p&gt;
{% endspaceless %}
</pre>
<p>这个例子将返回这样的HTML:</p>
<pre class="literal-block">

&lt;p&gt; &lt;a href=&quot;foo/&quot;&gt;Foo&lt;/a&gt; &lt;/p&gt;
</pre>
<p>只有 <em>标签</em> 之间的空白被处理 &#8212; 标签与文本之间的空白不会被处理.在下面这个例子里, <tt class="docutils literal"><span class="pre">Hello</span></tt> 周围的空白不会被缩小:</p>
<pre class="literal-block">

{% spaceless %}
    &lt;strong&gt;
        Hello
    &lt;/strong&gt;
{% endspaceless %}
</pre>
</div>
<div class="section">
<h3><a id="ssi" name="ssi">ssi</a></h3>
<p>在页面中输出给定文件的内容.</p>
<p>类似一个简单的 &quot;include&quot; 标签, <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">ssi</span> <span class="pre">%}</span></tt> 包含另一个文件的内容 &#8212; 不过必须在当前页面指定一个绝对路径</p>
<pre class="literal-block">

{% ssi /home/html/ljworld.com/includes/right_generic.html %}
</pre>
<p>如果提供了可选的 &quot;parsed&quot; 参数, 被包含文件的内容会使用当前的上下文作为模板代码进行求值处理.:</p>
<pre class="literal-block">

{% ssi /home/html/ljworld.com/includes/right_generic.html parsed %}
</pre>
<p>注意如何你使用 <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">ssi</span> <span class="pre">%}</span></tt>, 出于安全考虑, 你需要在你的 <tt class="docutils literal"><span class="pre">Django</span> <span class="pre">settings</span></tt> 文件中定义 <a class="reference" href="http://www.djangoproject.com/documentation/settings/#allowed-include-roots">ALLOWED_INCLUDE_ROOTS</a> .</p>
<p>参阅: <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">include</span> <span class="pre">%}</span></tt>.</p>
</div>
<div class="section">
<h3><a id="templatetag" name="templatetag">templatetag</a></h3>
<p>输出一个组成模板标签的字符.</p>
<p>由于模板系统没有 &quot;转义&quot; 的概念, 要显示一个组成模板标签的字符, 你必须使用 <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">templatetag</span> <span class="pre">%}</span></tt> 标签.</p>
<p>用参数告诉标签输出哪些内容:</p>
<blockquote>
<table class="docutils" border="1">
<colgroup>
<col width="72%" />
<col width="28%" /></colgroup>
<thead valign="bottom">
<tr>
<th class="head">参数</th>
<th class="head">输出</th>
</tr>
</thead>
<tbody valign="top">
<tr>
<td><tt class="docutils literal"><span class="pre">openblock</span></tt></td>
<td><tt class="docutils literal"><span class="pre">{%</span></tt></td>
</tr>
<tr>
<td><tt class="docutils literal"><span class="pre">closeblock</span></tt></td>
<td><tt class="docutils literal"><span class="pre">%}</span></tt></td>
</tr>
<tr>
<td><tt class="docutils literal"><span class="pre">openvariable</span></tt></td>
<td><tt class="docutils literal"><span class="pre">{{</span></tt></td>
</tr>
<tr>
<td><tt class="docutils literal"><span class="pre">closevariable</span></tt></td>
<td><tt class="docutils literal"><span class="pre">}}</span></tt></td>
</tr>
<tr>
<td><tt class="docutils literal"><span class="pre">openbrace</span></tt></td>
<td><tt class="docutils literal"><span class="pre">{</span></tt></td>
</tr>
<tr>
<td><tt class="docutils literal"><span class="pre">closebrace</span></tt></td>
<td><tt class="docutils literal"><span class="pre">}</span></tt></td>
</tr>
</tbody>
</table>
</blockquote>
</div>
<div class="section">
<h3><a id="widthratio" name="widthratio">widthratio</a></h3>
<p>要创建柱形图的话, 这个标签计算给定值与最大值的比率再乘以100,四舍五入为整数,最后输出这个整数.</p>
<p>例子:</p>
<pre class="literal-block">

&lt;img src=&quot;bar.gif&quot; height=&quot;10&quot; width=&quot;{% widthratio this_value max_value 100 %}&quot; /&gt;
</pre>
<p>上例中, 如果 <tt class="docutils literal"><span class="pre">this_value</span></tt> 是 175 而 <tt class="docutils literal"><span class="pre">max_value</span></tt> 是 200, 则上例中的图片应该是 88 像素宽 (因为 175/200 = .875; .875 * 100 = 87.5 四舍五入为 88).</p>
</div>
</div>
<div class="section">
<h2><a id="id9" name="id9">内建过滤器参考</a></h2>
<div class="section">
<h3><a id="add" name="add">add</a></h3>
<p>返回参数与被处理数据相加的结果.</p>
</div>
<div class="section">
<h3><a id="addslashes" name="addslashes">addslashes</a></h3>
<p>给敏感字符添加斜线(转义). 举例,要将一个字符串传递给 JavaScript 时..</p>
</div>
<div class="section">
<h3><a id="capfirst" name="capfirst">capfirst</a></h3>
<p>大写被处理数据的第一个字母.</p>
</div>
<div class="section">
<h3><a id="center" name="center">center</a></h3>
<p>按给定宽度将待处理数据居中.</p>
</div>
<div class="section">
<h3><a id="cut" name="cut">cut</a></h3>
<p>将待处理数据中的所有子串删除(该子串等于 cut 的参数)</p>
</div>
<div class="section">
<h3><a id="date" name="date">date</a></h3>
<p>根据给定的格式(与 <tt class="docutils literal"><span class="pre">now</span></tt> 标签相同)格式化一个日期.</p>
</div>
<div class="section">
<h3><a id="default" name="default">default</a></h3>
<p>如果值不可用,使用提供的默认值.</p>
</div>
<div class="section">
<h3><a id="default-if-none" name="default-if-none">default_if_none</a></h3>
<p>如果值为 <tt class="docutils literal"><span class="pre">None</span></tt>, 使用这个给定的默认值.</p>
</div>
<div class="section">
<h3><a id="dictsort" name="dictsort">dictsort</a></h3>
<p>接受一个字典列表,返回按给定参数的属性排序后的列表.</p>
</div>
<div class="section">
<h3><a id="dictsortreversed" name="dictsortreversed">dictsortreversed</a></h3>
<p>接受一个字典列表,返回按给定参数的属性逆序排序后的列表.</p>
</div>
<div class="section">
<h3><a id="divisibleby" name="divisibleby">divisibleby</a></h3>
<p>如果值可以被参数除尽,则返回 True.</p>
</div>
<div class="section">
<h3><a id="escape" name="escape">escape</a></h3>
<p>对一个字符串的敏感字符进入转义(以用于HTML). 特别是它会做如下替换:</p>
<blockquote>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">&quot;&amp;&quot;</span></tt> to <tt class="docutils literal"><span class="pre">&quot;&amp;amp;&quot;</span></tt></li>
<li><tt class="docutils literal"><span class="pre">&lt;</span></tt> to <tt class="docutils literal"><span class="pre">&quot;&amp;lt;&quot;</span></tt></li>
<li><tt class="docutils literal"><span class="pre">&gt;</span></tt> to <tt class="docutils literal"><span class="pre">&quot;&amp;gt;&quot;</span></tt></li>
<li><tt class="docutils literal"><span class="pre">'&quot;'</span></tt> (double quote) to <tt class="docutils literal"><span class="pre">'&amp;quot;'</span></tt></li>
<li><tt class="docutils literal"><span class="pre">&quot;'&quot;</span></tt> (single quote) to <tt class="docutils literal"><span class="pre">'&amp;#39;'</span></tt></li>
</ul>
</blockquote>
</div>
<div class="section">
<h3><a id="filesizeformat" name="filesizeformat">filesizeformat</a></h3>
<p>将值格式化为 &#8216;可读性好的&#8217; 文件大小(比如 <tt class="docutils literal"><span class="pre">'13</span> <span class="pre">KB'</span></tt>, <tt class="docutils literal"><span class="pre">'4.1</span> <span class="pre">MB'</span></tt>, <tt class="docutils literal"><span class="pre">'102bytes'</span></tt> 等等).</p>
</div>
<div class="section">
<h3><a id="first" name="first">first</a></h3>
<p>返回列表中的第一个元素.</p>
</div>
<div class="section">
<h3><a id="fix-ampersands" name="fix-ampersands">fix_ampersands</a></h3>
<p>将 <tt class="docutils literal"><span class="pre">&amp;</span></tt> 符号替换为 <tt class="docutils literal"><span class="pre">&amp;amp;</span></tt> 实体.</p>
</div>
<div class="section">
<h3><a id="floatformat" name="floatformat">floatformat</a></h3>
<p>将一个浮点数四舍五入到小数点后1位 &#8212; 如果根本没有小数,小数部分不会显示.例如:</p>
<blockquote>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">36.123</span></tt> 被转换成 <tt class="docutils literal"><span class="pre">36.1</span></tt></li>
<li><tt class="docutils literal"><span class="pre">36.15</span></tt> 被转换成 <tt class="docutils literal"><span class="pre">36.2</span></tt></li>
<li><tt class="docutils literal"><span class="pre">36</span></tt> 被转换成 <tt class="docutils literal"><span class="pre">36</span></tt></li>
</ul>
</blockquote>
</div>
<div class="section">
<h3><a id="get-digit" name="get-digit">get_digit</a></h3>
<p>提供一个完整的数, 返回该数中被请求的数字,其中 1 是最右边的数, 2 是从右边数第二个数字等等. 若输入值非法(若输入或参数不是整数, 或者参数小于1)则返回其原始值. 否则输出就总是整数.</p>
</div>
<div class="section">
<h3><a id="join" name="join">join</a></h3>
<p>用一个字符串将一个列表连接起来, 类似 Python 的 <tt class="docutils literal"><span class="pre">str.join(list)</span></tt>.</p>
</div>
<div class="section">
<h3><a id="length" name="length">length</a></h3>
<p>返回值的长度. 对列表特别有用.</p>
</div>
<div class="section">
<h3><a id="length-is" name="length-is">length_is</a></h3>
<p>若值的长度与参数相等,返回 True, 否则返回 False.</p>
</div>
<div class="section">
<h3><a id="linebreaks" name="linebreaks">linebreaks</a></h3>
<p>将换行符转化为 &lt;p&gt; 和 &lt;br /&gt;.</p>
</div>
<div class="section">
<h3><a id="linebreaksbr" name="linebreaksbr">linebreaksbr</a></h3>
<p>将换行符转化为 &lt;br /&gt;.</p>
</div>
<div class="section">
<h3><a id="linenumbers" name="linenumbers">linenumbers</a></h3>
<p>带行号显示文本.</p>
</div>
<div class="section">
<h3><a id="ljust" name="ljust">ljust</a></h3>
<p>在给定宽度的域内将文本左对齐.</p>
<p><strong>参数:</strong> 域宽度</p>
</div>
<div class="section">
<h3><a id="lower" name="lower">lower</a></h3>
<p>将字符串转化为小写.</p>
</div>
<div class="section">
<h3><a id="make-list" name="make-list">make_list</a></h3>
<p>将值转化为一个列表.对一个整数,它是一个数字的列表.对一个字符串,这是一个字符的列表.</p>
</div>
<div class="section">
<h3><a id="phone2numeric" name="phone2numeric">phone2numeric</a></h3>
<p>将一个电话号码(可能包含字母)转化等价的数字值.比如: <tt class="docutils literal"><span class="pre">'800-COLLECT'</span></tt> 将被转化为 <tt class="docutils literal"><span class="pre">'800-2655328'</span></tt>.</p>
<p>输入不一定非是一个合法号码. 它可以转化任意字符串.</p>
</div>
<div class="section">
<h3><a id="pluralize" name="pluralize">pluralize</a></h3>
<p>如果值不是 1 的话返回 &#8216;s&#8217; 用于 &#8217;1 vote&#8217; vs. &#8217;2 votes&#8217; 这种场合. 例如:</p>
<pre class="literal-block">

you have {{number_messages}} mail{{number_messages|pluralize}}.
(对中国人用处不大，嘿嘿）
</pre>
</div>
<div class="section">
<h3><a id="pprint" name="pprint">pprint</a></h3>
<p>pprint.pprint 和一个封装器&#8211; 仅用于调试.</p>
</div>
<div class="section">
<h3><a id="random" name="random">random</a></h3>
<p>返回随机的从列表中返回一个元素</p>
</div>
<div class="section">
<h3><a id="removetags" name="removetags">removetags</a></h3>
<p>从输出中删除单空格分隔的 [X]HTML标签 列表</p>
</div>
<div class="section">
<h3><a id="rjust" name="rjust">rjust</a></h3>
<p>在给定宽度的域内将文本右对齐.</p>
<p><strong>参数:</strong> 域大小</p>
</div>
<div class="section">
<h3><a id="slice" name="slice">slice</a></h3>
<p>返回一个列表的片段.</p>
<p>使用与 Python 的 list 相同的语法, 参阅 <a class="reference" href="http://diveintopython.org/native_data_types/lists.html#odbchelper.list.slice">http://diveintopython.org/native_data_types/lists.html#odbchelper.list.slice</a> 以了解更详细的信息.</p>
<p>示例: <tt class="docutils literal"><span class="pre">{{</span> <span class="pre">some_list|slice:&quot;:2&quot;</span> <span class="pre">}}</span></tt></p>
</div>
<div class="section">
<h3><a id="slugify" name="slugify">slugify</a></h3>
<p>转化为小写, 移去非单词字符(字母数字和下划线),将空白转化为连字符,去除前后空白.</p>
</div>
<div class="section">
<h3><a id="stringformat" name="stringformat">stringformat</a></h3>
<p>根据给定参数(一个格式字符串)格式化一个变量, 这个格式字符串使用 Python 字符串格式化语法, 例外之处是 &quot;%&quot; 运算符被省略.</p>
<p>参阅 <a class="reference" href="http://docs.python.org/lib/typesseq-strings.html">http://docs.python.org/lib/typesseq-strings.html</a> 以了解 Python 格式字符串</p>
</div>
<div class="section">
<h3><a id="striptags" name="striptags">striptags</a></h3>
<p>过滤掉[X]HTML标签.</p>
</div>
<div class="section">
<h3><a id="time" name="time">time</a></h3>
<p>根据给定的格式, 格式化一个时间(与 <tt class="docutils literal"><span class="pre">now</span></tt> 标签使用的格式相同).</p>
</div>
<div class="section">
<h3><a id="timesince" name="timesince">timesince</a></h3>
<p>格式化一个日期,这个日期是从给定日期到现在的天数和小时数(比如: &quot;4 days, 6 hours&quot;).</p>
<p>接受一个可选的参数，该参数是一个包含比较日期的变量（该参数默认值是 <em>now</em>). 举例来说， 如果 <tt class="docutils literal"><span class="pre">blog_date</span></tt> 是一个日期实例表示 2006-06-01 午夜， 而 <tt class="docutils literal"><span class="pre">comment_date</span></tt> 是一个日期实例表示 2006-06-01 早上8点，那么 <tt class="docutils literal"><span class="pre">{{</span> <span class="pre">comment_date|timesince:blog_date</span> <span class="pre">}}</span></tt> 将返回 &quot;8 hours&quot;.</p>
</div>
<div class="section">
<h3><a id="timeuntil" name="timeuntil">timeuntil</a></h3>
<p>类似 <tt class="docutils literal"><span class="pre">timesince</span></tt>, 只是它比较当前时间直到给定日期时间。举例来说，如果今天是 2006-06-01 而 <tt class="docutils literal"><span class="pre">conference_date</span></tt> 是 2006-06-29, 那么 <tt class="docutils literal"><span class="pre">{{</span> <span class="pre">conference_date|timeuntil</span> <span class="pre">}}</span></tt> 将返回 &quot;28 days&quot;.</p>
<p>接受一个可选的参数，该参数是一个包含比较日期的变量（该参数默认值是 <em>now</em>). 举例来说， 如果 <tt class="docutils literal"><span class="pre">from_date</span></tt> 是一个日期实例表示 2006-06-22， 那么 <tt class="docutils literal"><span class="pre">{{</span> <span class="pre">conference_date|timeuntil:from_date</span> <span class="pre">}}</span></tt> 会返回 &quot;7 days&quot;.</p>
</div>
<div class="section">
<h3><a id="title" name="title">title</a></h3>
<p>按标题格式转化一个字符串</p>
</div>
<div class="section">
<h3><a id="truncatewords" name="truncatewords">truncatewords</a></h3>
<p>将一个字符串截短为指定数目的单词.</p>
<p><strong>参数:</strong> 要保留的单词数</p>
</div>
<div class="section">
<h3><a id="unordered-list" name="unordered-list">unordered_list</a></h3>
<p>递归的接受一个自嵌套的列表并返回一个HTML无序列表(此列表可不是pythob语义中的列表) &#8212; 只是没有开始和结束的&lt;ul&gt;标签.</p>
<p>假定该列表是合适的格式. 举例来说, 如果 <tt class="docutils literal"><span class="pre">var</span></tt> 的值为 <tt class="docutils literal"><span class="pre">['States',</span> <span class="pre">[['Kansas',</span> <span class="pre">[['Lawrence',</span> <span class="pre">[]],</span> <span class="pre">['Topeka',</span> <span class="pre">[]]]],</span> <span class="pre">['Illinois',</span> <span class="pre">[]]]]</span></tt>, 那么 <tt class="docutils literal"><span class="pre">{{</span> <span class="pre">var|unordered_list</span> <span class="pre">}}</span></tt> 就会返回:</p>
<pre class="literal-block">

&lt;li&gt;States
&lt;ul&gt;
        &lt;li&gt;Kansas
        &lt;ul&gt;
                &lt;li&gt;Lawrence&lt;/li&gt;
                &lt;li&gt;Topeka&lt;/li&gt;
        &lt;/ul&gt;
        &lt;/li&gt;
        &lt;li&gt;Illinois&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
</pre>
</div>
<div class="section">
<h3><a id="upper" name="upper">upper</a></h3>
<p>将一个字符串全部转为大写.</p>
</div>
<div class="section">
<h3><a id="urlencode" name="urlencode">urlencode</a></h3>
<p>转义该值以用于 URL.</p>
</div>
<div class="section">
<h3><a id="urlize" name="urlize">urlize</a></h3>
<p>将普通文本的 URL 转化为可点击的链接.</p>
</div>
<div class="section">
<h3><a id="urlizetrunc" name="urlizetrunc">urlizetrunc</a></h3>
<p>将 URL 转化为一个可点击的链接, 根据给定的字符数截短 URL.</p>
<p><strong>参数:</strong> URL长度</p>
</div>
<div class="section">
<h3><a id="wordcount" name="wordcount">wordcount</a></h3>
<p>返回单词数</p>
</div>
<div class="section">
<h3><a id="wordwrap" name="wordwrap">wordwrap</a></h3>
<p>在指定行长将文字折行.</p>
<p><strong>参数:</strong> 行长(以字符计)</p>
</div>
<div class="section">
<h3><a id="yesno" name="yesno">yesno</a></h3>
<p>提供一个字符串参数对应着 true, false 和 (可选的) None, 根据被处理的值返回相应的字符串:</p>
<table class="docutils" border="1">
<colgroup>
<col width="15%" />
<col width="33%" />
<col width="52%" /></colgroup>
<thead valign="bottom">
<tr>
<th class="head">Value</th>
<th class="head">Argument</th>
<th class="head">Outputs</th>
</tr>
</thead>
<tbody valign="top">
<tr>
<td><tt class="docutils literal"><span class="pre">True</span></tt></td>
<td><tt class="docutils literal"><span class="pre">&quot;yeah,no,maybe&quot;</span></tt></td>
<td><tt class="docutils literal"><span class="pre">yeah</span></tt></td>
</tr>
<tr>
<td><tt class="docutils literal"><span class="pre">False</span></tt></td>
<td><tt class="docutils literal"><span class="pre">&quot;yeah,no,maybe&quot;</span></tt></td>
<td><tt class="docutils literal"><span class="pre">no</span></tt></td>
</tr>
<tr>
<td><tt class="docutils literal"><span class="pre">None</span></tt></td>
<td><tt class="docutils literal"><span class="pre">&quot;yeah,no,maybe&quot;</span></tt></td>
<td><tt class="docutils literal"><span class="pre">maybe</span></tt></td>
</tr>
<tr>
<td><tt class="docutils literal"><span class="pre">None</span></tt></td>
<td><tt class="docutils literal"><span class="pre">&quot;yeah,no&quot;</span></tt></td>
<td><tt class="docutils literal"><span class="pre">&quot;no&quot;</span></tt> (如果没有对应 None 的字符串,就将 None 转化为 False 处理</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="section">
<h1><a id="tags-filter" name="tags-filter">其它 tags 和 filter 库</a></h1>
<p>Django 自带了几个其它的模板 tag 库，要使用这些 tag 库，必须显式的在 <tt class="docutils literal"><span class="pre">INSTALLED_APPS</span></tt> 设置中启用他们，然后在模板中使用 <tt class="docutils literal"><span class="pre">{%</span> <span class="pre">load</span> <span class="pre">%}</span></tt> tag 载入他们.</p>
<div class="section">
<h2><a id="django-contrib-humanize" name="django-contrib-humanize">django.contrib.humanize</a></h2>
<p>一堆 Django 模板过滤器，用于生成易读的数据，参阅 <a class="reference" href="http://www.djangoproject.com/documentation/add_ons/#humanize">humanize documentation</a>.</p>
</div>
<div class="section">
<h2><a id="django-contrib-markup" name="django-contrib-markup">django.contrib.markup</a></h2>
<p>一堆模板过滤器，支持以下常见标记语言:：</p>
<blockquote>
<ul class="simple">
<li>Textile</li>
<li>Markdown</li>
<li>ReST (ReStructured Text)</li>
</ul>
</blockquote>
</div>
</div>
</div>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://pwwang.com/2010/03/26/django_templates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>淡腾的python字符串</title>
		<link>http://pwwang.com/2010/03/19/f_ucking_python_string/</link>
		<comments>http://pwwang.com/2010/03/19/f_ucking_python_string/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 08:36:42 +0000</pubDate>
		<dc:creator>pwwang</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://pwwang.com/?p=863</guid>
		<description><![CDATA[&#160;

接触Python，被Tkinter吸引。

因为项目要求，从LAMP（Linux + Apache + MySQL + PHP）转战至XAPPD（自己乱取的，纯属娱乐，Windows/Linux + Apache + PostgreSQL + Python + Django）。

<span class="readmore"><a href="http://pwwang.com/2010/03/19/f_ucking_python_string/" title="淡腾的python字符串">Read More: 1215 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>接触Python，被Tkinter吸引。</p>
<p>因为项目要求，从LAMP（Linux + Apache + MySQL + PHP）转战至XAPPD（自己乱取的，纯属娱乐，Windows/Linux + Apache + PostgreSQL + Python + Django）。</p>
<p>以前只是瞄过Python，但并未写过Python的东东。一直觉着Perl和Python其实是差不多的东西。当然大家都有自己鼓吹的一套。比如Perl会说它是正则表达式的鼻祖（事实上也是如此），Python则说Perl的语法晦涩难懂，自己语法清晰等等。包括Jquery鼓吹地说用链式写法改变javascript的编码习惯等等，各有一套说辞。但实际上，其实优缺点明白人心知肚明。至于你想用哪一套，那正是所谓萝卜白菜，各有所爱。</p>
<p>回归正题吧，看官们可以纯粹把此文看作是牢骚文。也许是编码习惯的改变，也许是平台的问题（我用Perl没出问题啊，呵呵）。情况是这样的：</p>
<p><span id="more-863"></span>上面提到我转战XAPPD，实属被转战。我仍然忠实于LAMPP。其中有一个重要的原因，那就是因为LAMPP有apachefriends提供的套装XAMPP，一键安装+配置。但是XAPPD得一个一个安装，一个一个配置，中间还不能出错。安装完成之后，我不想让apache和pgsql开机就启动，所以就想要一个这样的控制面板。</p>
<p><a href="http://pwwang.com/wp-content/uploads/2010/03/apachepgsql.jpg"><img alt="apache&amp;pgsql" title="apache&amp;pgsql" width="152" height="300" border="0" src="http://pwwang.com/wp-content/uploads/2010/03/apachepgsql-152x300.jpg" /></a><a href="http://pwwang.com/wp-content/uploads/2010/03/apachepgsql1.jpg"><img alt="apache&amp;pgsql1" title="apache&amp;pgsql1" width="153" height="300" border="0" style="clear=all" src="http://pwwang.com/wp-content/uploads/2010/03/apachepgsql1-153x300.jpg" /></a></p>
<p>看核心编程看到Tkinter那一块的时候就心动了，于是动手，就拿Python就当练手。</p>
<p>其他方面都还好，包括Tkinter的排版和事件。但是就是有字符串让我淡腾了。</p>
<p>执行Pgsql的start，restart，status，stop的命令行字符串经过我淡腾的调试，最后通过的Python代码：</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">pgData          = <span style="color: #483d8b;">'&quot;D:<span style="color: #000099; font-weight: bold;">\P</span>rogram Files&quot;<span style="color: #000099; font-weight: bold;">\P</span>ostgreSQL<span style="color: #000099; font-weight: bold;">\8</span>.4<span style="color: #000099; font-weight: bold;">\d</span>ata'</span>
pgsqlExe        = r<span style="color: #483d8b;">'D:<span style="color: #000099; font-weight: bold;">\&quot;</span>Program Files&quot;<span style="color: #000099; font-weight: bold;">\P</span>ostgreSQL<span style="color: #000099; font-weight: bold;">\8</span>.4<span style="color: #000099; font-weight: bold;">\b</span>in<span style="color: #000099; font-weight: bold;">\p</span>g_ctl.exe -D '</span> + pgData
pgsqlStatusCmd  = pgsqlExe + <span style="color: #483d8b;">' status'</span>
pgsqlStartCmd   = pgsqlExe + <span style="color: #483d8b;">' start'</span>
pgsqlStopCmd    = pgsqlExe + <span style="color: #483d8b;">' stop'</span>
pgsqlRestartCmd = pgsqlExe + <span style="color: #483d8b;">' restart'</span></pre></div></div>

</p>
<p>以下几种情况均报错：</p>
<p>D:\Program&nbsp;不是内部或外部命令，也不是可运行的程序或。。。。</p>
<p>1. pgData前加r的</p>
<p>2. pgsqlExe中双引号引用整个pg_ctl路径的</p>
<p>3. pgsqlExe中双引号引用D:\Program Files的</p>
<p>以下这种情况，运行status时不报错，但是运行start的报错：</p>
<p>pgData的双引号仅引用Program Files</p>
<p>pg_ctl报错说未知的模式，它把pgData中的Program Files给拆开了，D:后的\被吃掉了。。。</p>
<p>不就是跑个命令吗，至于设这么多关卡。。。</p>
<p>牢骚一下，话说回来，要是在*nix下就没有这样的问题了。</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://pwwang.com/2010/03/19/f_ucking_python_string/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

