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

murad :

I have some function based view for chat that i want to transform to class based view

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

This is a simple TemplateView [Django-doc]:

from django.views.generic import TemplateView

class ShowChatPage(TemplateView):
    template_name = 'chat_screen.html'

Normally the URL parameters are already passed to the template as well, since the basic get method [GitHub] is implemented as:

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

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=404763&siteId=1