Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django 基于类的视图覆盖泛型视图方法_Django_Django Class Based Views - Fatal编程技术网

Django 基于类的视图覆盖泛型视图方法

Django 基于类的视图覆盖泛型视图方法,django,django-class-based-views,Django,Django Class Based Views,我试着让它工作: url(r'^index$', Index.as_view(), name='index'), url(r'^index/(?P<pk>[0-9]+)$', Index.as_view(), name='index'), 源自 class MyViewBase(TemplateView, DetectMobileMixin, TemplateResponseMixin, ContextMixin): 默认情况下,它是渲染模板,但我为Index class jso

我试着让它工作:

url(r'^index$', Index.as_view(), name='index'),
url(r'^index/(?P<pk>[0-9]+)$', Index.as_view(), name='index'),
源自

class MyViewBase(TemplateView, DetectMobileMixin, TemplateResponseMixin, ContextMixin):
默认情况下,它是渲染模板,但我为
Index

class jsonMixin(object):
def get(self, *args, **kwargs):
    if 'pk' in kwargs:
        if self.request.is_ajax():
            pk = kwargs['pk']
            data = self.data_json(pk)
            json_data = json.dumps(data)
            return HttpResponse(json_data,content_type='application/json')
        else:
            self.context["pokaz_element"] = self.id
    return super().get(*args, **kwargs)

class Index(MyViewBase,  jsonMixin):
    ...
    def data_json():
        data = []
        ...
        return data
但它似乎不起作用。 我不知道怎么咬它

我试图理解基于类的视图是如何工作的,从中派生出什么,调用哪个函数
get
等等,但手册没有对此进行解释


我真的想在一个类中实现这一点

我认为应该将mixin放在MyViewBase之前,因为Python方法是查找的

class Index(jsonMixin, MyViewBase):
    ...
    def data_json():
        data = []
        ...
        return data
希望有助于

类索引(jsonMixin,MyViewBase)
??
class Index(jsonMixin, MyViewBase):
    ...
    def data_json():
        data = []
        ...
        return data