寻觅生命中的那一片浅草......

每月存档 十月, 2012

[zz]尝试PyTenjin --号称最快的Python 模板库

官网在这里http://www.kuwata-lab.com/tenjin/

曾经使用过Kid、Cheeth、Web2py的模 板,目前使用Mako和Django(Jinjia)。曾经非常的欣赏Web2py的模板,无论代码还是实际的html代码对coder都异常的友好,符 合自己‘想当然’这个库评价标准。但是因为Web2py没有将他的模板独立(好像后来,Limodou的Uliweb将这个库改造后独立了出来),且尚确 是不少功能,就放弃了。

今天看到PyTenjin又有了那种感觉:).

好了,来看代码,

<?py # -*- coding: utf-8 -*- ?>
<?py
from setting import *
from tenjin.helpers.html import *
?>
<?xml version=”1.0″ encoding=”utf-8″?>
<feed xmlns=”http://www.w3.org/2005/Atom”>
<title>#{ SITE_TITLE }</title>
<subtitle>#{SITE_SUB_TITLE}</subtitle>
<link rel=”alternate” type=”text/html” href=”http://#{curdomain}/” />
<link rel=”self” type=”application/atom+xml” href=”http://#{curdomain}/index.xml” />
<id>http://#{curdomain}/</id>
<updated>#{site_updated}</updated>
<rights>Copyright © 2010, #{ SITE_TITLE }</rights>
<?py for topic in posts: ?>
<entry>
<title>${ topic.title}</title>
<link rel=”alternate” type=”text/html” href=”http://#{curdomain}/p/#{topic.key().id()}” />
<id>tag:#{curdomain},#{topic.created.strftime(“%Y-%m-%d)”) }}:/p/#{topic.key().id()}</id>
<published>#{topic.created.strftime(“%Y-%m-%dT%H:%M:%SZ”)}</published>
<updated>#{topic.last_modified.strftime(“%Y-%m-%dT%H:%M:%SZ”)}</updated>
<author>
<name>#{topic.author_name}</name>
<uri>http://#{curdomain}/member/#{topic.author_name}</uri>
</author>
<content type=”html” xml:base=”http://#{curdomain}/” xml:lang=”en”><![CDATA[
#{urlize(myimg(nl2br(topic.short_con)))}
]]></content>
</entry>
<?py #endfor ?>
</feed>

是不是很想当然!

1,单行语句python代码 <?py  xxxxx  ?>

2,块Block语句 python代码

<?py if xxxx?>

XXXXX

<?py #endif?>

————————————————

<?py for xxx ?>

<?py #endfor?>

3, 变量 #{}不含HTML Escape转换 和 ${} 含HTML Escape转换

4, 条件判断表达式必须和if, while ..等在一行写

5,Python代码的缩进必须是4个空格

6, <?PY ?>里是预编译的语句,这些语句只会被执行一次,里面的变量和函数不能被<?py ?>、#{}和${}所用,也不能使用<?py ?>和模板参数中的变量和函数。
7, #{{}}和${{}}用法和#{}、${}类似,但只能使用<?PY ?>中的变量和函数。
8, 子模板可以用include()函数载入。

调用生成hmtl字串和习惯很相象

engine = tenjin.Engine(path=[os.path.join(‘template’, THEME), ‘template’], cache=tenjin.MemoryCacheStorage())
return engine.render(template, context, globals, layout)

原文在:http://hi.baidu.com/ghiewa/item/2f4ecf300306d3b8623affec

通过sudo运行PyCharm

我普通用户打开PyCharm,编辑root的代码,提示无法保存
当我
sudo /usr/local/pycharm/bin/pycharm.sh

提示找不到
Can’t connect to X11 window server using ‘:0’ as the value of the DISPLAY variable.

解决办法,通过2步操作解决这个问题

1、第一步
X11 Server权限问题

通过以下命令运行本地所有程序访问X11

xhost + local:all

执行后,如果提示
non-network local connections being added to access control list
则表示成功,为了方便,你可以把这命令加到~/.bashrc里,启动就加载

2、第二步
环境变量问题
X11的连接,依赖环境变量DISPLAY

env |grep DISPLAY
可以看到输出是
DISPLAY=:0

但sudo的时候,并没有设置这个环境变量

sudo env |grep DISPLAY

是没有输出的

为了设置这个环境变量,我们有2个解决办法

a、修改/usr/local/pycharm/bin/pycharm.sh

在脚本开头加入
export DISPLAY=:0

b、修改sudo配置

sudo /usr/sbin/visudo

找到Defaults env_keep

在最后加入DISPLAY

推荐款免费等宽字体

适合用于SecureCRT,Linux下的字体,很好看!

名字叫SourceCodePro!

2012年十月
« 9月   11月 »
1234567
891011121314
15161718192021
22232425262728
293031