Skip to content

Instantly share code, notes, and snippets.

@mindsocket
Created November 22, 2011 12:09
Show Gist options
  • Save mindsocket/1385520 to your computer and use it in GitHub Desktop.
Save mindsocket/1385520 to your computer and use it in GitHub Desktop.
Basic web.py backend for @themaninblue's DrawPad
import web
import json
urls = (
'/', 'index',
'/post', 'post',
'/data', 'data',
)
def add_global_hook():
g = web.storage({"paths": []})
def _wrapper(handler):
web.ctx.globals = g
return handler()
return _wrapper
app = web.application(urls, globals())
app.add_processor(add_global_hook())
class index:
def GET(self):
raise web.redirect('/static/index.htm')
class post:
def POST(self):
input = json.loads(web.data())
web.ctx.globals.paths.append(input)
print len(web.ctx.globals.paths)
return "ok"
class data:
def GET(self):
web.header('Content-Type', 'application/json')
result = json.dumps(web.ctx.globals.paths)
web.ctx.globals.paths = []
return result
web.webapi.internalerror = web.debugerror
if __name__ == "__main__":
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment