本文整理汇总了Python中django.template.response.TemplateResponse.set_signed_cookie方法的典型用法代码示例。如果您正苦于以下问题:Python TemplateResponse.set_signed_cookie方法的具体用法?Python TemplateResponse.set_signed_cookie怎么用?Python TemplateResponse.set_signed_cookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.template.response.TemplateResponse
的用法示例。
在下文中一共展示了TemplateResponse.set_signed_cookie方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: home
# 需要导入模块: from django.template.response import TemplateResponse [as 别名]
# 或者: from django.template.response.TemplateResponse import set_signed_cookie [as 别名]
def home (request):
da = DriveAuth(request)
creds = da.get_credentials(check_cookie=False)
if creds is None:
return da.redirect_auth()
c = {
'CLIENT_ID': settings.PRIV_GOOGLE_API_CLIENT_ID.split('.')[0],
}
response = TemplateResponse(request, 'editor.html', c)
expires = datetime.utcnow() + timedelta(seconds=settings.MAX_AGE)
response.set_signed_cookie(
settings.USERID_COOKIE,
value=da.userid,
salt=settings.PRIV_SALT
)
return response
示例2: edit
# 需要导入模块: from django.template.response import TemplateResponse [as 别名]
# 或者: from django.template.response.TemplateResponse import set_signed_cookie [as 别名]
def edit (request):
error = request.REQUEST.get('error', '')
if error == 'access_denied':
return TemplateResponse(request, 'main/access_denied.html', {})
da = DriveAuth(request)
creds = da.get_credentials(check_cookie=False)
if creds is None:
return da.redirect_auth()
state = request.REQUEST.get('state', '')
open_ids = []
new_in = None
if state:
state = json.loads(state)
if state["action"] == 'open':
if "exportIds" in state:
return TemplateResponse(request, 'main/not_supported.html', {})
elif "ids" in state:
open_ids = state["ids"]
elif state["action"] == 'create' and "parentId" in state:
new_in = state['parentId']
if da.prefs.save_session and da.prefs.session:
for oid in da.prefs.session.split(','):
if oid not in open_ids:
open_ids.append(oid)
recent_files = OrderedDict()
for f in FileOpen.all().filter("userid =", da.userid).order("-created").fetch(30):
if f.fileid not in recent_files:
recent_files[f.fileid] = f.filename
if len(recent_files) >= 10:
break
c = {
'MODES': MODES,
'NDEBUG': settings.NDEBUG,
'CLIENT_ID': settings.GOOGLE_API_CLIENT_ID.split('.')[0],
'prefs': da.prefs,
'themes': ETHEMES,
'sizes': ESIZES,
'binds': EKBINDS,
'wraps': EWRAPS,
'open_ids': open_ids,
'new_in': new_in,
'recent_files': recent_files
}
response = TemplateResponse(request, 'main/edit.html', c)
expires = datetime.datetime.utcnow() + datetime.timedelta(seconds=settings.MAX_AGE)
response.set_signed_cookie(
settings.USERID_COOKIE,
value=da.userid,
salt=settings.SALT,
expires=expires,
secure=settings.CSRF_COOKIE_SECURE,
httponly=False,
)
return response