class IndexTemplateView(TemplateView):
'''Index TemplateView.'''
template_name = 'frontend/index.html'
def post(self, request, *args, **kwargs):
'''Manages credentials received for methods calling authentication.'''
bitrix24_domain = request.GET.get('DOMAIN')
request.session['bitrix24_domain'] = bitrix24_domain
print(request.session['bitrix24_domain']) # String is stored and printed to the screen.
return redirect('index')
# Bitrix24 sends credentials via POST right after GET request.
# CSRF protection would cause error in this case.
@csrf_exempt
def dispatch(self, request, *args, **kwargs):
return super().dispatch(request, *args, **kwargs)
class LoginTemplateView(TemplateView):
'''Login TemplateView.'''
template_name = 'frontend/login.html'
def get(self, request, *args, **kwargs):
'''Renders the login page.'''
redirect_uri = get_google_redirect_uri()
print(request.session.items()) # Returns empty session. The string was never saved.
return redirect(redirect_uri)
我已经尝试设置request.session.modified = True
,但是它也不起作用。我真的不知道为什么我不能在会话中存储字符串。我也曾尝试在POST请求中存储在self.request
中,但没有成功,尝试将其存储在dispatch()函数中的setup()函数中。尝试了几乎所有内容,我无法在会话中存储任何信息。我也在使用Django Rest框架。
有人可以帮助我如何使用具有通用视图的会话吗?
问题已解决,会话不适用于Ngrok的隧道服务。