易截截图软件、单文件、免安装、纯绿色、仅160KB

python的wiki 列子.

#coding=utf-8
from newtest.wiki.models import WiKi
from django.template import loader, Context
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response

def index(request, pagename=""):
"""显示正常页面,对页面的文字做特殊的链接处理"""
if pagename:
#查找是否已经存在页面
pages = WiKi.objects.filter(pagename=pagename)
if pages:
#存在则调用页面模板进行显示
return process('wiki/page.html', pages[0])
else:
#不存在则进入编辑画面
return render_to_response('wiki/edit.html', {'pagename':pagename})
else:
page = WiKi.objects.get(pagename='FrontPage')
return process('wiki/page.html', page)

def edit(request, pagename):
"""显示编辑存在页面"""

page = WiKi.objects.get(pagename=pagename)
return render_to_response('wiki/edit.html', {'pagename':pagename, 'content':page.content})

def save(request, pagename):
"""保存页面内容,老页面进行内容替换,新页面生成新记录"""
content = request.POST['content']

pages = WiKi.objects.filter(pagename=pagename)
if pages:
pages[0].content = content
pages[0].save()
else:
page = WiKi(pagename=pagename, content=content)
page.save()
return HttpResponseRedirect("/wiki/%s" % pagename)

import re

r = re.compile(r'\b(([A-Z]+[a-z]+){2,})\b')
def process(template, page):
"""处理页面链接,并且将回车符转为"""

t = loader.get_template(template)

content = r.sub(r'<a href="/wiki/\1" mce_href="wiki/\1">\1</a>', page.content)
#content=re.sub(r'\b(([A-Z]+[a-z]+){2,})\b',r'<a href="/wiki/\1" mce_href="wiki/\1">\1</a>',page.content)
content = re.sub(r'[\r\n]+', '<br>', content)
c = Context({'pagename':page.pagename, 'content':content},autoescape=False)
return HttpResponse(t.render(c))

views.py
from django.conf.urls.defa


相关文档:

Python 二进制文件读取显示

filename=raw_input('enter file name:')
f=open(filename,'rb')
f.seek(0,0)
index=0
for i in range(0,16):
print "%3s" % hex(i) ,
print
for i in range(0,16):
print "%-3s" % "#" ,
print
while True:
temp=f.read(1)
if len(temp) == 0:
break
else:
print "%3s" % temp.encode('hex'),
......

python中获得某月有多少天的函数

  偶然需要用到这样一个函数,在Delphi中,有现成的函数可以调用!在python中,我找了半天都还没找到,最后自己写了一个函数如下:
def dayOfMonth(date):
if date.month == 12:
return 31
else:
return (date.replace(month=date.month+1, day=1) - datetime.timedelta(days=1)).day
......

python中的列表排序操作

 
 
 
Python lists have a built-in sort() method that modifies the list in-place and a sorted() built-in function that builds a new sorted list from an iterable.
There are many ways to use them to sort data and there doesn't appear to be a single, central place in the various man ......

Python Socket 编程

client:
import socket, sys
if __name__ == '__main__':
    #处理参数
    argv = sys.argv
    if (len(argv)!=3) or (len(argv)==2 and argv[1]=='/?'):
        print '>>>Useage:', argv[0], '<address> < ......

Python: 使用装饰器“@”取得函数执行时间

  Python中可以使用装饰器对函数进行装饰(或说包装),利用这个特性,可以很方便、简洁地解决一些问题,比如获得函数执行时间的问题。
  首先,我们定义一个函数,如下:
  def exeTime(func):
def newFunc(*args, **args2):
t0 = time.time()
print "@%s, {%s} start" % (time.strftime("%X", time.local ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号