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 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?

Deepak

password_hashing.py
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):
    username
    email
    password
    created
    is_admin

    class Meta:
        database = DATABASE
        order_by('-created',)

def set_password(user, password):
    user=User()
    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
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
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.