所以我正在处理保存配置文件功能,我不知道为什么我会收到以下错误:
__init__() takes at least 3 arguments (3 given)
这是它发生的功能(在它到达self.profiles.update line
之后):
@view_config(route_name="profile", request_method='POST')
def save_profile(self):
try:
json = self.request.json_body
#username = str(json['userName'])
first_name = str(json['firstName'])
last_name = str(json['lastName'])
phones = str(json['phones'])
emails = str(json['emails'])
self.profiles.update(self, firstName=first_name, lastName=last_name, emails=emails, phones=phones)
value = {'result:': 'success', 'message': 'Profile Saved!'}
self.respond(value)
return self.route('profile')
except Exception, err:
print err
value = {'result:': 'error', 'message': 'There was an error processing the request'}
self.respond(value)
return self.route('profile')
扩展控制台:
我在项目范围内搜索 init ,这似乎是唯一匹配的函数
class WhoView(Extension):
def __init__(self, context, request):
self.session = request.session
self.request = request
self.status_code = 200
self.content_type = "text/html"
ctx = self.session.ctx
self.request_context = context
Extension.__init__(self, ctx)
def attach_session(self, token):
self.ctx.attach_session(token)
有什么想法?您需要了解的其他信息?
答案 0 :(得分:2)
你没有在任何地方重定向(self.route进行重定向)。此外,您无法在此重定向,因为您正在进行ajax调用。我很确定电话和电子邮件的分配是不正确的,因为你正在将数组转换为字符串。我们明天会在办公室谈谈这件事。同样正如sza所指出的那样,你不会为方法调用传递self。
@view_config(route_name="profile", request_method='POST')
def save_profile(self):
try:
json = self.request.json_body
#username = str(json['userName'])
first_name = str(json['firstName'])
last_name = str(json['lastName'])
phones = str(json['phones'])
emails = str(json['emails'])
self.profiles.update(firstName=first_name, lastName=last_name, emails=emails, phones=phones)
value = {'result:': 'success', 'message': 'Profile Saved!'}
except Exception, err:
print err
value = {'result:': 'error', 'message': 'There was an error processing the request'}
#returns a json response
return self.respond(value)
答案 1 :(得分:1)
不是
self.profiles.update(self, firstName=first_name, lastName=last_name, emails=emails, phones=phones)
应该是
self.profiles.update(firstName=first_name, lastName=last_name, emails=emails, phones=phones)