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 Create User

Help me out with this challenge please, I aint got a clue what i have to do right now, Just short of time

I've set up most of a User resource for you but I want you to finish it.

Add two new requirements to the RequestParser for "password" and "confirm_password". Both should be required and in either "form" or "json" locations.

from flask import Blueprint

from flask.ext.restful import Resource, Api, reqparse, marshal_with, fields

import models

user_fields = {
    'username': fields.String

class UserList(Resource):
    def __init__(self):
        self.reqparse = reqparse.RequestParser()
            location=['form', 'json']

    def post(self):
        args = self.reqparse.parse_args()
        user = models.User.create(**args)
        return user, 201

users_api = Blueprint('resources.users', __name__)
api = Api(users_api)
api.add_resource(UserList, '/api/v1/users')

1 Answer

Louise St. Germain
Louise St. Germain
19,424 Points

Hi Elvin,

Your best bet would be to come back to this when you have more time, or to make time to sit down with this - you're definitely smart enough to figure this out, if you've gotten this far!

Give it a try, even if it doesn't work at first. The process of figuring out what does and doesn't work (as opposed to just being told) is extremely helpful in solidly learning a programming language or framework. The forum is especially helpful when you've tried a question and have some code that shows what your thinking process is. It's a lot easier for others to help if there's a specific problem they can help you get through.

In cases like this where you feel like you have no idea how to solve something (this happens to everyone!), I'd recommend you go back and review the previous video - or previous video(s) all the way back to the point where you got lost. There is definitely no shame in repeating videos or sections of videos. (Personally, I use that "go back 10 seconds" button a LOT! :-) ... and I've also had to repeat entire videos too.)

Stopping the videos as you go along to take notes is also really helpful, because you'll have notes you can refer to after. Also, if you don't understand the video, you will notice that it will become really hard to take notes because you don't know what to write, or you feel you don't understand what you're writing. That's a good sign that you need to go back and repeat that section.

If it's a case where you're having a hard time with the way it was explained, you could also try googling something like "python flask user resource tutorial" or just "python flask tutorial" - you will almost certainly be able to find some more information to supplement what's in the Treehouse lessons.

Anyway, I hope this helps a bit. I know you can do this challenge if you put your mind to it! :-)

okay thank you mame; i think that is what i will have to do!