Mercurial > genshi > mirror
comparison examples/webpy/hello.py @ 267:8165d6e3b703 trunk
Add [WebPy web.py] example app.
author | cmlenz |
---|---|
date | Mon, 25 Sep 2006 13:26:42 +0000 |
parents | |
children | d9d3b844442b |
comparison
equal
deleted
inserted
replaced
266:8a13cbab435e | 267:8165d6e3b703 |
---|---|
1 import os | |
2 from genshi.template import TemplateLoader | |
3 import web | |
4 | |
5 loader = TemplateLoader([os.path.dirname(os.path.abspath(__file__))], | |
6 auto_reload=True) | |
7 urls = ('/(.*)', 'hello') | |
8 | |
9 | |
10 class hello(object): | |
11 | |
12 def GET(self, name): | |
13 i = web.input(times=1) | |
14 if not name: | |
15 name = 'world' | |
16 name = name.decode('utf-8') | |
17 | |
18 tmpl = loader.load('hello.html') | |
19 stream = tmpl.generate(name=name, times=int(i.times)) | |
20 | |
21 web.header('Content-Type', 'text/html; charset=utf-8', unique=True) | |
22 for output in stream.serialize('html'): | |
23 print output.encode('utf-8') | |
24 | |
25 | |
26 if __name__ == '__main__': | |
27 web.internalerror = web.debugerror | |
28 web.run(urls) |