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 trialDiego Salas Polar
21,431 PointsI 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.
1 Answer
Chris Freeman
Treehouse Moderator 68,423 PointsHey 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
21,431 PointsI finally resolved the issue! Thanks Chris!
Chris Freeman
Treehouse Moderator 68,423 PointsChris Freeman
Treehouse Moderator 68,423 PointsHey Diego, can you post the entire error stack trace you're getting?