Django 从另一个基于类的视图调用基于类的视图

2024-02-26

我正在尝试调用基于类的视图并且我能够做到这一点,但由于某种原因我没有得到我正在调用的新类的上下文

class ShowAppsView(LoginRequiredMixin, CurrentUserIdMixin, TemplateView):
    template_name = "accounts/thing.html"



    @method_decorator(csrf_exempt)
    def dispatch(self, *args, **kwargs):
        return super(ShowAppsView, self).dispatch(*args, **kwargs)

    def get(self, request, username, **kwargs):
        u = get_object_or_404(User, pk=self.current_user_id(request))

        if u.username == username:
            cities_list=City.objects.filter(user_id__exact=self.current_user_id(request)).order_by('-kms')
            allcategories = Category.objects.all()
            allcities = City.objects.all()
            rating_list = Rating.objects.filter(user=u)
            totalMiles = 0
            for city in cities_list:
                totalMiles = totalMiles + city.kms

        return self.render_to_response({'totalMiles': totalMiles , 'cities_list':cities_list,'rating_list':rating_list,'allcities' : allcities, 'allcategories':allcategories})


class ManageAppView(LoginRequiredMixin, CheckTokenMixin, CurrentUserIdMixin,TemplateView):
    template_name = "accounts/thing.html"

    def compute_context(self, request, username):
        #some logic here                        
        if u.username == username:
            if request.GET.get('action') == 'delete':
                #some logic here and then:
                ShowAppsView.as_view()(request,username)

我做错了什么吗伙计们?


代替

ShowAppsView.as_view()(self.request)

我不得不这样做

return ShowAppsView.as_view()(self.request)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Django 从另一个基于类的视图调用基于类的视图 的相关文章

随机推荐