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 Tacocat Challenge The Challenge

Yosef Fastow
Yosef Fastow
18,526 Points

getting 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.)


def index():
    tacos = models.Taco.select().limit(100)
    return render_template('index.html', index=index)

@app.route('/new-taco', methods=('GET', 'POST'))
def tacos():
    form = forms.TacoForm()
    if form.validate_on_submit():
        return redirect(url_for('index'))
    return render_template('taco.html', form=form)


    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=[
    extras = TextAreaField("Add any other detail.", validators=[DataRequired()])


class Taco(Model):
    timestamp = DateTimeField(default=datetime.datetime.now)
    user = ForeignKeyField(
    protein = CharField()
    shell = CharField()
    cheese = CharField()
    extras = TextField()

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


{% extends 'layout.html' %}

{% block content %}
    {% if tacos.count() %}
        <table class="u-full-width">
        {% for taco in tacos %}
              <!-- taco attributes here -->
                {{ taco.protein }}
                {{ taco.cheese }}
                {{ taco.shells }}
                {{ taco.extras }}
        {% endfor %}
    {% else %}
        <!-- message for missing tacos -->
        <p>Sorry the site is new and empty pleases add and help us start our site!</p>
    {% endif %}
{% endblock %}
Yosef Fastow
Yosef Fastow
18,526 Points

the code you gave seemed to solve the problem, but now I'm getting peewee.OperationalError

peewee.OperationalError: no such column: t1.username

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 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
Chris Freeman
Treehouse Moderator 68,423 Points

Can 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.

def index():
    tacos = models.Taco.select().limit(100)
    return render_template('index.html', index=index, tacos=tacos)

Can you post your index.html?