我想调用基于类的视图,我能够做到这一点,但由于某种原因,我没有得到我打电话给我的新班级的背景从另一个基于类的视图Django调用基于视图
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)
我在做什么错家伙?
这是什么应该做的事情?通过简单地调用这个视图,你希望达到什么目的?我猜你可能需要返回调用它的结果,但由于'compute_context'是一个非标准方法,所以很难确定。 – 2013-02-19 11:47:31
我是一种“刷新”我的网页,所以我回想起我的上一页有一些新的上下文数据 – psychok7 2013-02-19 11:50:00
我正在返回返回self.render_to_response(self.compute_context(请求,用户名)) – psychok7 2013-02-19 11:50:27