[英]how can I extends from another class
I'm new in Python/Django and I'm working on a little project to improve my self, I would like to know how can I extends or how can I call a function from another class I already tried but I got some errors我是 Python/Django 的新手,我正在做一个小项目来提高自己,我想知道如何扩展或如何从另一个 class 调用 function 我已经尝试过但我遇到了一些错误
this is my code: first class这是我的代码:第一个 class
# Create your views here.
class ContactCenter(object):
def myFunction(self, logged_user_id = None):
print("hello")
second class第二 class
from apps.contact.views import ContactCenter
class ListModelMixin(object):
def list(self, request, *args, **kwargs):
ContactCenter.myFunction()
You can do that in two ways, one subclass if from ContactCenter
:您可以通过两种方式做到这一点,如果来自ContactCenter
一个子类:
class ListModelMixin(ContactCenter):
def list(self, request, *args, **kwargs):
self.myFunction()
Or call the function from an instance of ContactCenter
:或从ContactCenter
实例调用 function :
class ListModelMixin(object):
def list(self, request, *args, **kwargs):
instance = ContactCenter()
instance.myFunction()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.