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

Diego Salas Polar
Diego Salas Polar
16,296 Points

I am having jinja2.exceptions.UndefinedError: 'forms.TacoForm object' has no attribute 'cheese'.

I try to find the undefined error but no luck. The error occurs when your log in and you click "Create a Taco". I think I need Chris Freeman or Kenneth Love to help me out with this one. Here is the link to hard work of coding. Thanks for taking the time out of your day for helping me. Means a lot to me.

https://w.trhou.se/v286g9fk2r

Chris Freeman
Chris Freeman
Treehouse Moderator 68,154 Points

Hey Diego, can you post the entire error stack trace you're getting?

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,154 Points

Hey Diago,

Looking at the database, I don't see "cheese" in the taco model. The fields in the database for taco are "id", "timestamp", "user_id", "content", "user".

$ sqlite3 python.db                                                          
SQLite version 3.7.17 2013-05-20 00:56:22                                                         
Enter ".help" for instructions                                                                    
Enter SQL statements terminated with a ";"                                                        
sqlite> .dump taco                                                                                
PRAGMA foreign_keys=OFF;                                                                          
BEGIN TRANSACTION;                                                                                
CREATE TABLE "taco" ("id" INTEGER NOT NULL PRIMARY KEY, "timestamp" DATETIME NOT NULL, "user_id" I
NTEGER NOT NULL, "content" TEXT NOT NULL, FOREIGN KEY ("user_id") REFERENCES "user" ("id"));      
CREATE INDEX "taco_user_id" ON "taco" ("user_id");                                                
COMMIT;

Removing the database python.db and letting it be reinitialized corrected the database:

treehouse:~/workspace$ sqlite3 python.db                                                          
SQLite version 3.7.17 2013-05-20 00:56:22                                                         
Enter ".help" for instructions                                                                    
Enter SQL statements terminated with a ";"                                                        
sqlite> .dump taco                                                                                
PRAGMA foreign_keys=OFF;                                                                          
BEGIN TRANSACTION;                                                                                
CREATE TABLE "taco" ("id" INTEGER NOT NULL PRIMARY KEY, "timestamp" DATETIME NOT NULL, "user_id" I
NTEGER NOT NULL, "protein" VARCHAR(100) NOT NULL, "chesse" SMALLINT NOT NULL, "shell" VARCHAR(100)
 NOT NULL, "extras" TEXT NOT NULL, FOREIGN KEY ("user_id") REFERENCES "user" ("id"));             
CREATE INDEX "taco_user_id" ON "taco" ("user_id");                                                
COMMIT;                                                                                           
sqlite>                                                                                           

After this, it still didn't work. But looking closer at the above output I saw the field name "chesse" (two 's'), which is driven by the model definition:

class Taco(Model):
  timestamp = DateTimeField(default=datetime.datetime.now)
  user = ForeignKeyField(
    rel_model=User,
    related_name='tacos'
  )
  protein = CharField(max_length=100)
  chesse = BooleanField()  # <-- This "chesse" stands alone!

Fixing the typo and recreating the database, resolved the issue! Good luck with the rest of the challenge!

Diego Salas Polar
Diego Salas Polar
16,296 Points

I finally resolved the issue! Thanks Chris!