11 2011 档案

摘要:django模版中的截断过滤器想输出一段摘要,需要用到截断过滤器,查阅了官方文档发现truncatewords方法但是这个方法只能按照词【空格】 来截断需要的内容。不能按照字符长度截断。官方竟然没有提供相关的功能。For example:{{ value|truncatewords:2 }} If value is "Joel is a slug", the output will be "Joel is ...". Newlines within the string will be removed.{{ value|truncatewords_htm 阅读全文
posted @ 2011-11-23 20:53 LemonLi 阅读(1063) 评论(0) 推荐(0)
摘要:使用HTMLParser去除HTML源文件中的标签和属性在一些情况下,比如输出一片文章的摘要,前面的若干个字,但是存储在数据库中的文章又 偏偏是带有格式的HTML。这种情况下,可以使用下面这种方法将HTML中所有的标签剔除干净。from HTMLParser import HTMLParserdef strip_tags(html): html=html.strip() html=html.strip("\n") result=[] parse=HTMLParser() parse.handle_data=result.append parse.feed(h... 阅读全文
posted @ 2011-11-23 20:34 LemonLi 阅读(1431) 评论(0) 推荐(0)
摘要:在django模版渲染中过滤传入的值当中的HTML标签Django内置的filter,有一个是removetags,可以过滤多个指定的Html标签,比如博客的内容摘要可能是html格式的,显示的时候,去掉a p span div标签,可以这样写{{blog.content|removetags:"a p span div"}} removetags函数会去掉指定的标签,注意 | 两边都不能留空格。 阅读全文
posted @ 2011-11-23 20:29 LemonLi 阅读(1083) 评论(0) 推荐(0)
摘要:django在命令行下执行的脚本使用ORM项目中遇到一个东西需要写一个deamon来处理,需要在deamon脚本中使用到djangoORM来操作数据库,这样就需要在deamon script中初始化一个django environment# settings.pyfrom os.path import joinimport os.pathsettings_path = os.path.abspath(os.path.dirname(__file__))# deamon.pyimport sysimport settingsfrom django.core.management import s 阅读全文
posted @ 2011-11-22 14:41 LemonLi 阅读(960) 评论(0) 推荐(0)
摘要:建立代码仓库init config$ git init当前目录被称为工作树$ git config --global user.name "Your Name Comes Here"$ git config --global user.email you@yourdomain.example.com设置用户名和邮箱,此信息会保存在每次commit的log中,使用git log察看常用操作add commit revert$ git add .将当前目录生成一个快照放到一个临时存储区域,创建索引$ echo "zh" > .gitignore$ gi 阅读全文
posted @ 2011-11-20 12:16 LemonLi 阅读(1028) 评论(0) 推荐(0)
摘要:既然用上emacs了当然要学会怎么用emacs做笔记一个详细的教程http://markdown.tw/本想就用大纲模式算了, google了一下发现了markdown这个好东西先说下安装首先下载 markdown-mode.elhttp://jblevins.org/projects/markdown-mode/markdown-mode.el按照注释中提到的方法将下列代码加入.emacs配置中 (autoload 'markdown-mode "markdown-mode.el" "Major mode for editing Markdown fil 阅读全文
posted @ 2011-11-20 00:16 LemonLi 阅读(3339) 评论(0) 推荐(0)
摘要:逼自己在Ubuntu+emacs的环境下做了一周的开发慢慢的对emacs熟悉了起来,但是有一些快捷键还是没用熟练 总结下常用的按键命令作用C-fforward-char向前一个字符C-bbackward-char向后一个字符C-pprevious-line上移一行C-nnext-line下移一行M-fforward-word向前一个单词M-bbackward-word向后一个单词C-abeginning-of-line移到行首C-eend-of-line移到行尾M-eforward-sentence移到句首M-abackward-sentence移到句尾M-}forward-paragraph 阅读全文
posted @ 2011-11-19 22:19 LemonLi 阅读(458) 评论(0) 推荐(0)
摘要:1.memcached安装使用apt-get安装memcached# sudo apt-get install memcached启动一个memcached实例# memcached -m 10 -p 12000-m 10 是指定最多使用的内存大小单位是M,如果不指定默认会使用64M-p 12000 是指定端口号,默认端口为11211另一个例子 说明一下参数memcached -d -m 10 -u root -l 192.168.40.4 -p 12000 -c 256 -P /tmp/memcached.pid参数说明:-d选项是启动一个守护进程-m是分配给Memcache使用的内存数量. 阅读全文
posted @ 2011-11-18 12:45 LemonLi 阅读(2638) 评论(0) 推荐(1)
摘要:1、安装samba:# sudo apt-get install samba2、查看windows下共享打印机的共享名(注意:不是在windows添加的打印机的名字,而是共享名。可以通过在windows下添加好打印机后,在”开始”->”打印机和传真”,选择那台共享打印机。右键,属性->共享。那里的共享名就是我们想要的)名字中的空格用%20代替3、进入ubuntu。在system(系统)->Printer(打印),AddPrinter(添加打印机).4、选择”NetworkPrinter(网络打印机)”->”使用samba的window打印机”5、可能会弹出几个密码输入框 阅读全文
posted @ 2011-11-18 11:16 LemonLi 阅读(1961) 评论(0) 推荐(0)