Created
February 3, 2014 16:44
-
-
Save orestis/8787408 to your computer and use it in GitHub Desktop.
This file contains 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
from bottle import Bottle, template, request, run | |
app = Bottle() | |
@app.route('/hello/') | |
def greet(): | |
return template(''' | |
<html> | |
<body> | |
Please introduce yourself: | |
<form action="/knock" method="POST"> | |
<input type="text" name="name" /> | |
<input type="submit" /> | |
</body> | |
</html>''', name=name) | |
@app.post('/knock') | |
def knock(): | |
name = request.forms.get('name') | |
# this is the only new code added in our wsgi app | |
app.broadcast_message("{} knocked".format(name)) | |
return template("<p>{{ name }} Knocked!</p>", name=name) | |
wsgi_app = app | |
if __name__ == '__main__': | |
run(app, host='localhost', port=8005) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment