@route('/login')
def login ():
username = request .forms .get('username ')
password = request .forms .get('password ')
if check_user_credentials(username, password):
response .set_cookie("account", username, secret= 'some-secret-key')
return "Welcome %s!You are now logged in." % username
else :
return "Login failed."
@route('/restricted')
def restricted_area ():
username = request .get_cookie("account", secret= 'some-secret-key')
if username:
return "Hello %s.Welcome back." % username
from bottle import request, response
@route('/login', method="POST")
def login():
user = request.POST['user']
passwd = request.POST['passwd']
if check_user_right(user,passwd):
response.COOKIES['account'] = user
else:
pass
@route('/admin')
def admin():
user = request.COOKIES['user']
if user:
pass
@route('/archrives/:aid#\d+#')
def article_show(aid):
db = dbconn.ConnDB()
artid = int(aid)
# 获取客户端ip
remoteip = request.environ.get('REMOTE_ADDR')
artcookie = remoteip+'ip'+aid
print request.COOKIES.keys()
# 判断cookie是否存在
if artcookie in request.COOKIES.keys():
# 存在则更新有效时间
response.COOKIES[artcookie] = True
response.COOKIES[artcookie]['max-age'] = 500
else:
# 不存在则更新文章查看次数
db.posts.update({"id":artid}, {"$inc":{"views":1}})
# 并设置cookie
response.COOKIES[artcookie] = True
response.COOKIES[artcookie]['max-age'] = 500
TEMPLATE['posts'] = getArtList({"id":artid})
TEMPLATE.update(setTempVar())
return template('article.html', TEMPLATE)
from bottle import response help(response.set_cookie)
:param domain: the domain that is allowed to read the cookie. (default: current domain) :param path: limits the cookie to a given path (default: current path)
from bottle import request, response
@route('/login', method="POST")
def login():
user = request.POST['user']
passwd = request.POST['passwd']
if check_user_right(user,passwd):
response.COOKIES['account'] = user
response.COOKIES['account']['path'] = '/admin'
else:
pass
@route('/admin')
def admin():
user = request.COOKIES['user']
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有