Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.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 有没有办法在ListView中调用函数?_Django_Python 2.7 - Fatal编程技术网

Django 有没有办法在ListView中调用函数?

Django 有没有办法在ListView中调用函数?,django,python-2.7,Django,Python 2.7,我有一个ListView,我想在每次输入ListView或定期使用python执行一个脚本来更新我们的数据库 有办法吗 class AccessPointList(generic.ListView): #receives the whole set of AccessPoint and send to HTML model = AccessPoint #call a function in python -> c.update() #or create a def to update ou

我有一个ListView,我想在每次输入ListView或定期使用python执行一个脚本来更新我们的数据库

有办法吗

class AccessPointList(generic.ListView): #receives the whole set of AccessPoint and send to HTML
model = AccessPoint
#call a function in python -> c.update()
#or create a def to update our database

当然,当您想要运行它时,只需重写其中一个方法,然后调用super继续正常执行ListView

class AccessPointList(generic.ListView):
    model = AccessPoint

    def get(self, request, *args, **kwargs):
        # call your function
        return super().get(request, *args, **kwargs)

谢谢你,伙计,看起来很管用。但是现在我对super()有一个问题。因为我使用的是Python2.7,所以它要求有一个参数。这可能是一些简单的东西,但我真的是Django的初学者。我想。。。我们必须用self
response=super(AccesPointList,self)调用这个类。get(request,*args,**kwargs)
这个响应是因为get方法返回对列表的响应。啊,是的,super需要python 2中的参数。在python3中,可以将其留空