Frage

so I'm working on a save profile feature and I'm not sure why I'm getting the following error:

__init__() takes at least 3 arguments (3 given)


This is the function it happens in (right after it hits the 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')

enter image description here

The expanded console:

enter image description here

I did a project wide search for init and this seems like the only function that matches

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)

Any thoughts? Additional info you need to see?

War es hilfreich?

Lösung

You're not redirecting anywhere (self.route does a redirect). Also, you can't redirect here because you're doing an ajax call. I'm pretty sure the assignment for phones and emails isn't correct because you're casting arrays to strings. We'll talk about it in the office tomorrow. Also as sza pointed out, you don't pass self for method calls.

@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)

Andere Tipps

Isn't

self.profiles.update(self, firstName=first_name, lastName=last_name, emails=emails, phones=phones)

should be

self.profiles.update(firstName=first_name, lastName=last_name, emails=emails, phones=phones)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top