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
相关文档:
1. 事件驱动
一个事件及其回调的例子是鼠标移动。我们假设鼠标指针停在您GUI 程序的某处。如果鼠标被移到了程序的别处,一定是有什么东西引起了屏幕上指针的移动,从而表现这种位置的转移。系统必须处理这些鼠标移动事件才能展现(并实现)鼠标在窗口上的移动。一旦您释放了鼠标,就不再会有事件需要处 ......
怎么找不到第三章的学习笔记了?丢了?
Python的函数没有什么的,可以说,看了《简明Python教程》后,就会写了。
这一章提供的内容也比《简明Python教程》要多一些。比较复杂的是作用域规则,不知道是书没讲清楚还是翻译得不好,比较难懂。钱能的《C++程序教程》关于函数的作用域规则讲得要清楚些,有C++的知识在里面, ......
昨天试了下用HTMLParser类来解析网页,可发现结果并不理想。不管怎么说,先写下过程,希望后来人能在此基础上解决我所遇到的问题。
写了2套解决方案,当然这2套只能对特定网站有效。我这里主要说明下对BBC主页www.bbc.co.uk和对网易www.163.com的解析。
对于BBC:
这套要简单得多,可能是该网页的编码比较标准吧
import ......
继前篇《Import Module》(http://blog.csdn.net/xiadasong007/archive/2009/09/02/4512797.aspx),继续分析嵌入部分基础知识。这次不多说,有什么问题记得多查英文资料,国内的这方面知识少
还是来看代码,写完我就睡觉了~
#include "python/python.h"
#include <iostream>
using namespace std;
int ......