我有一个问题是我的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的对象传递给receieve方法,以便我可以在MessageNet类的receive方法中访问它们。
请告诉我为什么我会收到此错误。
答案 0 :(得分:2)
您在类而不是实例上调用实例方法。您需要实例化MessageNet
对象,然后在该实例上调用receive
,而不是在类上。
或者你可以使它成为一个类方法,但是你将无法访问任何实例属性(密码等)。
答案 1 :(得分:0)
您正在获取它,因为您正在将MessageGlobal
实例传递给MessageNet
上的方法。要么改为传递MessageNet
实例,要么将方法转换为普通函数。