Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Create User (Flask Rest APi)

Im annoyed, and I have been troubled by this challenge for a while and I do not know what to do. They are giving me this response "Couldn't create a user with a valid password"

Challenge Task 2 of 2

Now, inside of UserList.post, check that the "password" and "confirm_password" args are equal to each other. If they're not, raise an Exception. If they are equivalent, go ahead and create the user and send it back.

This is my response:

@marshal_with(user_fields)
def post(self):
    args = self.reqparse.parse_args()
    if args.get('password') == args.get('confirm_password'):
        user = models.User.create_user(**args)
        return marshal(user, user_fields), 201
    return make_response(json.dumps({'error':'Password and confirmation do not match'})), 400

3 Answers

Lukas Hölzer
Lukas Hölzer
37,349 Points

Hi Innocent,

you are doing great and you only have to change the line:

user = models.User.create_user(**args)

to

user = models.User.create(**args)
 @marshal_with(user_fields)
    def post(self):
        args = self.reqparse.parse_args()
        if args.get('password') == args.get('confirm_password'):
            user = models.User.create(**args)
            return marshal(user, user_fields), 201
        return make_response(json.dumps({'error': 'Password and confirm_password do not match'}), 400)

Worked well thanks Lukas

Khem Myrick
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Khem Myrick
Python Web Development Techdegree Graduate 18,701 Points

I wonder if someone at Treehouse could modify the wording on that question to make that clearer? That method could be named anything, (in the previous video, Kenneth named it create_user) and it would take some guesswork or coming here to realize it was simply called create. The name of an unseen method that isn't a standard issue default should preferably be explicitly given, not merely hinted at.