# HG changeset patch # User cmlenz # Date 1159190802 0 # Node ID 8165d6e3b703ec0bfc9533a89ace2ac5228ad42d # Parent 8a13cbab435e8b5a6bec044c1aac541ecc6c9b22 Add [WebPy web.py] example app. diff --git a/examples/webpy/README.txt b/examples/webpy/README.txt new file mode 100644 --- /dev/null +++ b/examples/webpy/README.txt @@ -0,0 +1,6 @@ +Sample application that demonstrates the use of Genshi templates in web.py +(http://webpy.org/). + +Try introducing errors (not just XML well-formedness errors, those are boring) +in the template, and you'll see a nice error screen with pretty good +information about the exact error. diff --git a/examples/webpy/hello.html b/examples/webpy/hello.html new file mode 100644 --- /dev/null +++ b/examples/webpy/hello.html @@ -0,0 +1,13 @@ + + + +

web.py with Genshi

+
+ + + diff --git a/examples/webpy/hello.py b/examples/webpy/hello.py new file mode 100644 --- /dev/null +++ b/examples/webpy/hello.py @@ -0,0 +1,28 @@ +import os +from genshi.template import TemplateLoader +import web + +loader = TemplateLoader([os.path.dirname(os.path.abspath(__file__))], + auto_reload=True) +urls = ('/(.*)', 'hello') + + +class hello(object): + + def GET(self, name): + i = web.input(times=1) + if not name: + name = 'world' + name = name.decode('utf-8') + + tmpl = loader.load('hello.html') + stream = tmpl.generate(name=name, times=int(i.times)) + + web.header('Content-Type', 'text/html; charset=utf-8', unique=True) + for output in stream.serialize('html'): + print output.encode('utf-8') + + +if __name__ == '__main__': + web.internalerror = web.debugerror + web.run(urls)