クラスベースのビューには、この機能ベースのビューを変換する方法?

ミュラド:

私は、クラスベースのビューに変換したいことを、私はチャットのためのいくつかの機能ベースのビューを持っています

def ShowChatPage(request,room_name,person_name):
    return render(request,"chat_screen.html",{'room_name':room_name,'person_name':person_name})
ウィレム・ヴァン・当社:

これは単純ですTemplateView[ジャンゴ-DOC]

from django.views.generic import TemplateView

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

通常、URLのパラメータは、基本的なことから、既に、同様にテンプレートに渡されるget方法[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 = self.get_context_data(**kwargs)
        return self.render_to_response(context)

おすすめ

転載: http://10.200.1.11:23101/article/api/json?id=405991&siteId=1