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 trialYosef Fastow
18,526 Pointsgetting a "UndefinedError: 'tacos' is undefined" in the tacocat challenge.
In the tacocat challenge any time I try to load the main page I get a Undefined Error: tacos is undefined. I'm not 100% done but its hard to go further because its hard to check progress if you can't see what the home page looks like. I'm not exactly sure what variable tacos represents.I guessed it represents the Taco class in the login. I attached the code below.
(Also the login, logout, register and post pages work.)
tacocat.py
@app.route('/')
def index():
tacos = models.Taco.select().limit(100)
return render_template('index.html', index=index)
@app.route('/new-taco', methods=('GET', 'POST'))
@login_required
def tacos():
form = forms.TacoForm()
if form.validate_on_submit():
models.Taco.create(user=g.user._get_current_object(),
protein=form.protein.data.strip(),
shell=form.shell.data.strip(),
cheese=form.cheese.data.strip(),
extra=form.extra.data.strip())
return redirect(url_for('index'))
return render_template('taco.html', form=form)
forms.py
class TacoForm(Form):
protein = StringField("What type of protein is in your taco? Beans? Beef?", validators=[DataRequired()])
shell = StringField("What type of shell is your taco?", validators=[DataRequired()])
cheese = StringField("Does it have cheese?", validators=[
DataRequired()
])
extras = TextAreaField("Add any other detail.", validators=[DataRequired()])
models.py
class Taco(Model):
timestamp = DateTimeField(default=datetime.datetime.now)
user = ForeignKeyField(
rel_model=User,
related_name='posts'
)
protein = CharField()
shell = CharField()
cheese = CharField()
extras = TextField()
class Meta:
database = DATABASE
order_by = ('-timestamp',)
index.html
{% extends 'layout.html' %}
{% block content %}
<h2>Tacos</h2>
{% if tacos.count() %}
<table class="u-full-width">
<thead>
<tr>
<th>Protein</th>
<th>Cheese?</th>
<th>Shell</th>
<th>Extras</th>
</tr>
</thead>
<tbody>
{% for taco in tacos %}
<tr>
<!-- taco attributes here -->
{{ taco.protein }}
{{ taco.cheese }}
{{ taco.shells }}
{{ taco.extras }}
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<!-- message for missing tacos -->
<p>Sorry the site is new and empty pleases add and help us start our site!</p>
{% endif %}
{% endblock %}
Chris Freeman
Treehouse Moderator 68,454 Points"No such column" errors are typically due to a new difference between the models and the database. if you changed the models recently, then you'll need to remake your database.
1 Answer
Chris Freeman
Treehouse Moderator 68,454 PointsCan you be very specific to what you are doing when you get be error and can you provide the detailed error message you are seeing?
In tacocat.py
above the indentation if the index
view is off. It needs to be unindented.
Also in the index
view, the value of tacos
is defined but not passed to the rendered template. If the template accesses {{ tacos }}
it might raise the error.
@app.route('/')
def index():
tacos = models.Taco.select().limit(100)
return render_template('index.html', index=index, tacos=tacos)
Can you post your index.html
?
Chris Freeman
Treehouse Moderator 68,454 Pointschanged to answer.
Yosef Fastow
18,526 PointsYosef Fastow
18,526 Pointsthe code you gave seemed to solve the problem, but now I'm getting peewee.OperationalError
peewee.OperationalError: no such column: t1.username