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
相关文档:
今天做ftp的界面,做的相当郁闷,弄得心情及其不爽,在网上搜到死都不知道该怎么办,打算明天先看看C++
的是怎么弄的再说。不过,现在我想写一下关于socket的编程。
先写一个时间服务器吧,他监听端口,并且会返回 服务器的时间
server.py
#!/usr/bin/python
# Copyright (c) angelipin (angelipin@126.com)
import ......
ZoundryDocument
Python skin is known for its color variations and for its elasticity; it is
the warmest leather of the season and ideal for the manufacture of many luxury
goods. Sometimes natural patterns can be hidden when they're done in black, but
the finish here has a bit of a shine to it ......
代码中采用了三步实现算术表达式的解析:
1. 将算术表达式(字符串)转换成一个列表parseElement方法
2. 将列表表示的算术表达式转换成后缀表达式changeToSuffix
3. 计算后缀表达式的结果
这里我是为了方便, 就写了个parseElement, 不想那方法写到后面却把自己绕住了, 可以想象一个带自增, 位, 逻辑, 算术的表达式的数值提 ......
1. 事件驱动
一个事件及其回调的例子是鼠标移动。我们假设鼠标指针停在您GUI 程序的某处。如果鼠标被移到了程序的别处,一定是有什么东西引起了屏幕上指针的移动,从而表现这种位置的转移。系统必须处理这些鼠标移动事件才能展现(并实现)鼠标在窗口上的移动。一旦您释放了鼠标,就不再会有事件需要处 ......
1. 打印变量和变量自显
>>> myString = 'Hello World!'
>>> print myString
Hello World!
>>> myString
'Hello World!'
因为: print 语句调用str()函数显示对象,而交互式解释器则调用repr()函数来显示对象
sys.stdout.write('hello')不会在末尾加上'\n',而print会
2. 打印文件
hand ......