Created
July 8, 2016 16:25
-
-
Save kurozumi/c3f556d99171641e95d2f61376c171d4 to your computer and use it in GitHub Desktop.
【Python】bottleでPOST送信
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 route, run, request | |
import os | |
@route("/login") | |
def login(): | |
return """ | |
<form action="/login" method="post"> | |
Username: <input name="username" type="text" /> | |
Password: <input name="password" type="password" /> | |
<input value="Login" type="submit" /> | |
</form> | |
""" | |
@route("/login", method="POST") | |
def do_login(): | |
username = request.forms.get("username") | |
password = request.forms.get("password") | |
if check_login(username, password): | |
return "<p>Your ligin infomation was correct.</p>" | |
else: | |
return "<p>Login failed.</p>" | |
def check_login(username, password): | |
if username == "user" and password == "pass": | |
return True | |
else: | |
return False | |
run(host="0.0.0.0", port=int(os.environ.get("PORT", 5000))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment