Django 会话不坚持通用视图

Django session not persisting with generic views

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 一样使用隧道服务。