Return to Snippet

Revision: 20182
at November 10, 2009 17:33 by manatlan


Updated Code
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import bottle as web # http://bottle.paws.de/page/docs
DEV=True
web.debug(DEV)


@web.route("/static/:path")
def static(path):
    web.send_file(path,root="static")

@web.route('/:name#.*#')
def index(name):
    name = name or "unknown"
    web.response.content_type = 'text/html; charset=utf-8'
    web.response.COOKIES['kiki'] = name
    return """hello %(name)s
            <a href='/do/show?a=1&a=2'>show</a>""" % locals()

@web.route('/do/:cmd?')
def cmd(cmd):
    if cmd=="show":
        yield "<li>cookies : %s</li>"% str(web.request.COOKIES)
        yield "<li>get : %s</li>"%     str(web.request.GET)
        yield "<li>post : %s</li>"%    str(web.request.POST)
    else:
        web.redirect("/") #don't work with yield now ;-(

@web.route('/.*')
def fallback():
    yield "my 404"
    #~ web.abort(404, "Not Found")

@web.error(500)             # don't work for me ?!?
def fallback500(err):
    return "my error:"+str(err)

def main(useGae=False):
    if useGae:
        from google.appengine.ext.webapp import util
        util.run_wsgi_app(web.default_app())
    else:
        web.run(reloader=DEV)

if __name__=="__main__":
    main()

Revision: 20181
at November 10, 2009 17:32 by manatlan


Updated Code
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import bottle as web # http://bottle.paws.de/page/docs
DEV=True
web.debug(DEV)


@web.route("/static/:path")
def static(path):
    web.send_file(path,root="static")

@web.route('/:name#.*#')
def index(name):
    web.response.content_type = 'text/html; charset=utf-8'
    a=12/0
    name = name or "unknown"
    web.response.COOKIES['kiki'] = name
    return """hello %(name)s
            <a href='/do/show?a=1&a=2'>show</a>""" % locals()

@web.route('/do/:cmd?')
def cmd(cmd):
    if cmd=="show":
        yield "<li>cookies : %s</li>"% str(web.request.COOKIES)
        yield "<li>get : %s</li>"%     str(web.request.GET)
        yield "<li>post : %s</li>"%    str(web.request.POST)
    else:
        web.redirect("/") #don't work with yield now ;-(

@web.route('/.*')
def fallback():
    yield "my 404"
    #~ web.abort(404, "Not Found")

@web.error(500)             # don't work for me ?!?
def fallback500(err):
    return "my error:"+str(err)

def main(useGae=False):
    if useGae:
        from google.appengine.ext.webapp import util
        util.run_wsgi_app(web.default_app())
    else:
        web.run(reloader=DEV)

if __name__=="__main__":
    main()

Revision: 20180
at November 9, 2009 05:59 by manatlan


Updated Code
#!/usr/bin/python
# -*- coding: utf-8 -*-
import bottle as web # http://bottle.paws.de/page/docs
DEV=True
web.debug(DEV)

@web.route('/:name?')
def index(name):
    name = name or "unknown"
    web.response.COOKIES['kiki'] = name
    return """hello %(name)s
            <a href='/do/show?a=1&a=2'>show</a>""" % locals()

@web.route('/do/:cmd')
def cmd(cmd):
    if cmd=="show":
        return "<li>cookies : %s</li>"%str(web.request.COOKIES)
        #~ return "<li>get : %s</li>"%str(web.request.GET)
        #~ return "<li>post : %s</li>"%str(web.request.POST)
    else:
        web.redirect("/")

@web.route('/.*')
def fallback():
    yield "my 404"
    #~ web.abort(404, "Not Found")

def main(useGae=False):
    if useGae:
        from google.appengine.ext.webapp import util
        util.run_wsgi_app(web.default_app())
    else:
        web.run(reloader=DEV)

if __name__=="__main__":
    main()

Revision: 20179
at November 9, 2009 05:57 by manatlan


Initial Code
#!/usr/bin/python
# -*- coding: utf-8 -*-
import bottle as web
DEV=True
web.debug(DEV)

@web.route('/:name?')
def index(name):
    name = name or "unknown"
    web.response.COOKIES['kiki'] = name
    return """hello %(name)s
            <a href='/do/show?a=1&a=2'>show</a>""" % locals()

@web.route('/do/:cmd')
def cmd(cmd):
    if cmd=="show":
        return "<li>cookies : %s</li>"%str(web.request.COOKIES)
        #~ return "<li>get : %s</li>"%str(web.request.GET)
        #~ return "<li>post : %s</li>"%str(web.request.POST)
    else:
        web.redirect("/")

@web.route('/.*')
def fallback():
    yield "my 404"
    #~ web.abort(404, "Not Found")

def main(useGae=False):
    if useGae:
        from google.appengine.ext.webapp import util
        util.run_wsgi_app(web.default_app())
    else:
        web.run(reloader=DEV)

if __name__=="__main__":
    main()

Initial URL
http://bottle.paws.de/page/docs

Initial Description
**work in progress**

Initial Title
python web with bottle

Initial Tags
python, web

Initial Language
Python