如何将这个基于函数的视图转换为基于 class 的视图?

How to transform this function based view to class based view?

我有一些基于功能的聊天视图,我想将其转换为基于 class 的视图

def ShowChatPage(request,room_name,person_name):
    return render(request,"chat_screen.html",{'room_name':room_name,'person_name':person_name})

这是一个简单的TemplateView [Django-doc]:

from django.views.generic import TemplateView

class ShowChatPage(TemplateView):
    <b>template_name = 'chat_screen.html'</b>

通常 URL 参数 也已经传递给模板,因为基本的 get method [GitHub] 实现为:

class TemplateView(TemplateResponseMixin, ContextMixin, View):
    """
    Render a template. Pass keyword arguments from the URLconf to the context.
    """
    def get(self, request, *args, **kwargs):
        context = <b>self.get_context_data(**kwargs)</b>
        return self.render_to_response(context)