Skip to content

Instantly share code, notes, and snippets.

@amigcamel
Last active August 21, 2016 08:19
Show Gist options
  • Select an option

  • Save amigcamel/73e3c8b1e124b56a15e948b1b58f2484 to your computer and use it in GitHub Desktop.

Select an option

Save amigcamel/73e3c8b1e124b56a15e948b1b58f2484 to your computer and use it in GitHub Desktop.
Python bottle test
# -*- coding: utf-8 -*-
from bottle import get, post, request, redirect, run
@get('/')
def index():
return '''
<div style="text-align:center;padding:200px;">
<h1>女友的話處處是坑,讓我們來幫你翻譯吧!</h1>
<br />
<form action="/" method="post">
如果女友說: <input name="text" type="text" size="50" />
<input value="他的意思是" type="submit" />
</form>
</div>
'''
@post('/')
def do_index():
text = request.forms.get('text')
return '''
<div style="text-align:center;padding:100px;">
<h1>女友說: {text}</h1>
<br>
<h2>其實他的意思是:</h2>
<p>你走開,我不想跟你說話!</p>
<form action="/response" method="post">
<input name="text" type="hidden" value="{text}" />
<input value="你可以這樣回應" type="submit" />
</form>
</div>
'''.format(text=text)
@get('/response')
def response():
redirect('/')
@post('/response')
def do_response():
text = request.forms.get('text')
return '''
<div style="text-align:center;padding:200px;">
<h3>如果女友說:{text}</h3>
<h4>你其實可以回:</h4>
<h1>假的!都是假的!</h1>
<div style="padding-top:100px;"><a href="/">回首頁</a></div>
</div>
'''.format(text=text)
run(host='0.0.0.0', port=8080, debug=True)
@amigcamel
Copy link
Author

Environments

Python 2.7.10
bottle 0.12.9

Deployment

python bottle_test.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment