我想調用基於類的視圖,我能夠做到這一點,但由於某種原因,我沒有得到我打電話給我的新班級的背景從另一個基於類的視圖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