0

我有一个问题是我的 django 视图

 def home(request):
        try:
            from_number  = request.GET['from_number']
            to_number  = request.GET['to_number']
            messagetext  = request.GET['msg_text']
            date_time  = request.GET['date_time']
            date_received  = request.GET['date_received']
            status = 0
        except:
            LOG_ERROR('Invalid Parameter')

            #Return to some product page or 500 error with message
            #pass    #  return some value  after discussing with sir 
     #      #Based on from number identify the Vmn and his class anc class the respective receieve method of that class
        if from_number !=None  and to_number != None:
            try:getvmn = ServiceProvider.objects.get(status = False)
            except:
                LOG_FATAL("VMN doesn't exists ")
                getvmn = False
            if getvmn:
                print "-=-=-=-=-==-=-=-==================="
    #           get_related_class = ServiceProvider.objects.filter(id  = getvmn.merchant,status = False)
                get_related_class = ServiceProvider.objects.get(status = False)
                b = SMSMgr()
                for objec in b._allsp:
                    if objec.class_Name == 'MessageNet':
                       # messageglobalobject  =     
                        MessageNet.receive(MessageGlobal(from_number,to_number,messagetext,date_received,status))

这是 smsmessage.py

class MessageGlobal():
    def __init__(self,from_number,to_number,messagetext,date,status = None):
        self.messagetext = messagetext
        self.to_number = to_number
        self.from_number = from_number
        self.date = date
        self.status = status

这是 MessageNet 类

class MessageNet():
    def __init__(self,username,password,sendingurl,class_Name):
        self.username = username
        self.password = password
        self.messagetext = None
        self.sendingurl = sendingurl
        self.class_Name = class_Name
        self.PhoneNumber = None
       # self.apiurl = apiurl

    def send(self,mg):

        payload = {'username': self.username, 'Pwd': self.password,'PhoneNumber':mg.tonumber,'PhoneMessage':mg.messagetext}
        r = requests.get(self.sendingurl, params=payload)
        LOG_INFO("Message sent to %s  via  %s", self.PhoneNumber,'Messagenet')
        #   Call to ms manager 

    def receive(self,getmessageobject):

        print "receive and notify the user "    

我收到错误消息

MessageNet.receive(MessageGlobal(from_number,to_number,messagetext,date_received,status))
of my views .

我正在尝试将 MessageGlobal 的对象传递给接收方法,以便我可以在 MessageNet 类的接收方法中访问它们。

请告诉我为什么会收到此错误。

4

2 回答 2

2

您在类而不是实例上调用实例方法。您需要实例化一个MessageNet对象,然后调用receive该实例,而不是类。

或者,您可以将其设为类方法,但您将无法访问任何实例属性(密码等)。

于 2013-02-06T18:28:50.433 回答
0

你得到它是因为你将一个MessageGlobal实例传递给MessageNet. 要么传递一个MessageNet实例,要么将方法转换为普通函数。

于 2013-02-06T08:22:36.257 回答