Last active
January 1, 2016 14:09
-
-
Save hideshi/8155642 to your computer and use it in GitHub Desktop.
This test drive is made by Bottle which is the light weight web application framework for Python.
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
from bottle import view, route, get, post, request, redirect, template, run | |
@route('/') | |
@view('index') | |
def index(): | |
return dict() | |
@route('/hello/<name>') | |
def index(name='World'): | |
return template('Hello {{name}}!', name=name) | |
@route('/<name>/<age:int>') | |
def greet(name, age): | |
return template('Hello {{name}}. You are {{age}} years old!', name=name, age=age) | |
@route('/wrong') | |
def wrong(): | |
return redirect('/right') | |
@route('/right') | |
def right(): | |
return 'right' | |
@get('/login') # or @route('/login') | |
def login_form(): | |
return '''<form method="POST" action="/login"> | |
<input name="name" type="text" /> | |
<input name="password" type="password" /> | |
<input type="submit" /> | |
</form>''' | |
@post('/login') # or @route('/login', method='POST') | |
def login_submit(): | |
name = request.forms.get('name') | |
password = request.forms.get('password') | |
if check_login(name, password): | |
return "<p>Logged in</p>" | |
else: | |
return "<p>Login failed</p>" | |
def check_login(name, password): | |
if name == password: | |
return True | |
else: | |
return False | |
run(host='localhost', port=8080, debug=True, reloader=True) |
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
<html> | |
<title>Test Page</title> | |
<body> | |
<h1 align="center">Hello world!</h1> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment