Skip to content

Instantly share code, notes, and snippets.

@fmasanori
Last active February 24, 2016 22:37
Show Gist options
  • Save fmasanori/5923012 to your computer and use it in GitHub Desktop.
Save fmasanori/5923012 to your computer and use it in GitHub Desktop.
tutorial bottle 04
import bottle
@bottle.route('/')
def home_page():
mythings = ['apple', 'orange', 'banana', 'peach']
return bottle.template('hello_world2', {'username':'Masanori',
'things':mythings})
@bottle.post('/favorite_fruit')
def favorite_fruit():
fruit = bottle.request.forms.get('fruit')
if fruit == None or fruit == '':
fruit = 'No Fruit Selected'
bottle.response.set_cookie('fruit', fruit)
bottle.redirect('/show_fruit')
@bottle.route('/show_fruit')
def show_fruit():
fruit = bottle.request.get_cookie('fruit')
return bottle.template('fruit_selection', {'fruit':fruit})
bottle.debug(True)
bottle.run(host='localhost', port = 8082)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment