Last active
August 21, 2016 08:19
-
-
Save amigcamel/73e3c8b1e124b56a15e948b1b58f2484 to your computer and use it in GitHub Desktop.
Python bottle test
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
| # -*- 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) | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Environments
Python 2.7.10bottle 0.12.9Deployment