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())