2

有沒有一種方法用戶dajaxice與基於django類的視圖? 我想這一點,但沒有多少成功:Dajaxice與基於類的視圖

class FavoriteEnroledTrainee(SessionMixin, View): 

    def get(self, request, *args, **kwargs): 
     print 'here' 

    @method_decorator(dajaxice_register(method='GET', name='company.favorite')) 
    def dispatch(self, *args, **kwargs): 
     return super(FavoriteEnroledTrainee, self).dispatch(*args, **kwargs) 

我可以看到dajaxice能夠獲取的觀點,但沒有被打印出來。

+0

您是否嘗試返回'HttpResponse'取代'print'? – iMom0

+0

是的,我做了,沒有成功 – Filipe

回答

3

您不能註冊調度方法,因爲它不是視圖入口點。 Dajaxice會嘗試直接調用dispatch,但這不起作用,因爲它不是一個完整的函數視圖。

你應該註冊* as_view *調用的結果:

class FavoriteEnroledTrainee(SessionMixin, View): 
    def get(self, request, *args, **kwargs): 
     print 'here' 
favorite_enroled_trainee = dajaxice_register(method='GET', name='company.favorite')(FavoriteEnroledTrainee.as_view())