forked from pfalcon/picoweb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_webapp.py
More file actions
29 lines (21 loc) · 748 Bytes
/
example_webapp.py
File metadata and controls
29 lines (21 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import re
import picoweb
def index(req, resp):
yield from resp.awrite("HTTP/1.0 200 OK\r\n")
yield from resp.awrite("Content-Type: text/html\r\n")
yield from resp.awrite("\r\n")
yield from resp.awrite("I can show you a table of <a href='squares'>squares</a>.")
def squares(req, resp):
yield from picoweb.start_response(resp)
yield from app.render_template(resp, "squares.tpl", (req,))
ROUTES = [
("/", index),
("/squares", squares),
("/file", lambda req, resp: (yield from picoweb.sendfile(resp, "picoweb.py"))),
(re.compile("^/sq"), index),
]
import logging
logging.basicConfig(level=logging.INFO)
#logging.basicConfig(level=logging.DEBUG)
app = picoweb.WebApp(__name__, ROUTES)
app.run(debug=True)