易截截图软件、单文件、免安装、纯绿色、仅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 Socket Server

今天做ftp的界面,做的相当郁闷,弄得心情及其不爽,在网上搜到死都不知道该怎么办,打算明天先看看C++
的是怎么弄的再说。不过,现在我想写一下关于socket的编程。
先写一个时间服务器吧,他监听端口,并且会返回 服务器的时间
server.py
#!/usr/bin/python
# Copyright (c) angelipin (angelipin@126.com)
import ......

Best Replica Gucci Galaxy Python Hobo Bag

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 ......

学习《Python语言入门》第四章 函数


怎么找不到第三章的学习笔记了?丢了?
Python的函数没有什么的,可以说,看了《简明Python教程》后,就会写了。
这一章提供的内容也比《简明Python教程》要多一些。比较复杂的是作用域规则,不知道是书没讲清楚还是翻译得不好,比较难懂。钱能的《C++程序教程》关于函数的作用域规则讲得要清楚些,有C++的知识在里面, ......

Python中的正则表达式基础

$  字符串的末尾
^  字符串的开始
\b  字符的边界
前缀t  字符串中的反斜线(所有字符)不转义
?  可选地匹配(位于之前的)单个字符
()  改变优先级,作为一个整体,一个组
|  或者
(A|B)  精确匹配A或B中的一个
{n,m}  匹配(位于之前的字符)n到m次
VERBOSE  ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号