Created
November 22, 2011 12:09
-
-
Save mindsocket/1385520 to your computer and use it in GitHub Desktop.
Basic web.py backend for @themaninblue's DrawPad
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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