Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Build a Social Network with Flask Making Strong Users Bcryptkeeper

build social network with flask bcrypt excercise

I am facing this error when trying to submit this solution.

I have tried 2 ways to solve this. @classmethod and instantiating the User class.

Has anyone else faced the same issue? What am I missing in my solution?


import datetime

from peewee import *
from flask_login import UserMixin
from flask.ext.bcrypt import generate_password_hash
from flask.ext.bcrypt import check_password_hash

class User(UserMixin, Model):

    class Meta:
        database = DATABASE

def set_password(user, password):
    user.username = user
    user.password = generate_password_hash(password)

    return user

3 Answers

I get the following error


ERROR: test_results (main.TestFunctionDefinitionExecution)

Traceback (most recent call last): File "", line 55, in test_results File "/workdir/utils/challenge.py", line 25, in execute_source exec(src) File "", line 9, in File "", line 10, in User NameError: name 'username' is not defined

Ran 1 test in 0.015s

FAILED (errors=1)

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

Hi there, Deepak Nautiyal! The method should be defined inside the User class. A lot of this comes down to indentation. Your set_password method should be indented inside User such that it lines up with the class Meta: line.

Hope this helps! :sparkles:

Thanks for the response, Jennifer. But this did not resolve the issue. I created the function within the class with proper indentation, however, I started getting a new error.