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 trialBala Selvam
Python Development Techdegree Student 30,590 PointsReally not sure what I'm doing wrong here. Can anyone clear this up for me?
I keep getting this message and not sure what it's talking about:
cannot import name 'User'
import datetime
from peewee import *
from argon2 import PasswordHasher
DATABASE = SqliteDatabase('recipes.db')
HASHER = PasswordHasher()
class Meta:
database = DATABASE
@classmethod
def create_user(cls, username, password):
try:
cls.get(cls.username**username)
except cls.DoesNotExist:
user = cls(username=username)
user.password = cls.hash_password(password)
user.save()
return user
else:
raise Exception("user already exists")
@staticmethod
def hash_password(password):
return HASHER.hash(password)
def verify_passowrd(self, password):
return HASHER.verify(self.password, password)
class Recipe(Model):
name = CharField()
created_at = DateTimeField(default=datetime.datetime.now)
class Meta:
database = DATABASE
class Ingredient(Model):
name = CharField()
description = CharField()
quantity = DecimalField()
measurement_type = CharField()
recipe = ForeignKeyField(Recipe)
class Meta:
database = DATABASE
def initialize():
DATABASE.connect()
DATABASE.create_tables([User, Recipe, Ingredient], safe=True)
DATABASE.close()
1 Answer
Jeff Muday
Treehouse Moderator 28,720 PointsYou are close! But somehow key parts of the code were deleted.
In particular--
You are missing the User class definition code that was given to you in step 1.
Also, some of the indentations of the class Meta
, @classmethod
, @staticmethod
, and def verify_password
blocks should indent these to be part of the User class you are adding.