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 Flask REST API API Protection User Resource

Richard Li
Richard Li
9,751 Points

Why use make_response on the password don't match return?

here in the User resource, why use make_response instead of just return the string of json?

the response it make didn't get used elsewhere so why use make_response?

def post(self):
        args = self.reqparse.parse_args()
        if args.get("password") == args.get("confirmed_password"):
            models.User.create_user(**args)
            return marshal(user, user_fields), 201
            #http code 201 created
        return make_response(
            json.dumps(
                {"error":"Password and confirm password do not match"}
            ), 400)