如何将此基于函数的视图转换为基于类的视图? [英] How to transform this function based view to class based view?

查看:38
本文介绍了如何将此基于函数的视图转换为基于类的视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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})

推荐答案

这是一个简单的通常, URL参数也已经传递到模板,因为基本的

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)

这篇关于如何将此基于函数的视图转换为基于类的视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆