Login in 登录
学什么编程语言的第一个都是hello world,做web的第一个应该就是login in 登录了吧
一:pro截图
二:index.py
from bottle import route, run, template, request
#登录
@route("/login",method="post")
def login():
username = request.forms.get("username");
password = request.forms.get("password");
print(username,password)
if username =='admin' and password =='admin':
return username+'登录成功';
else :
return username+'登录失败';
#用户登录页面的
@route("/index")
def index():
return template("index")
#@route('/hello/:name')
#def index(name='World'):
# return '<b>Hello %s!</b>' % name
#默认端口 run(host='localhost', port=8080)
run()
三:index.tpl
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="/login" method="post">
用户名:<input type="text" name="username" />
密码:<input type="password" name="password" />
</br><input type="submit" value='login'/>
</form>
</body>
</html>
四:效果
失败:
成功: