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!

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

Nthulane Makgato
Nthulane Makgato
Courses Plus Student 19,602 Points

Tacocat Code Challenge won't pass. "Bummer! Try Again!"


I have passed all 11 tests in the workspaces version of tacocat.py but the challenge won't pass. I have commented out the app.run() section of my code.

Chris Freeman, Kenneth Love or anyone else. Your assistance would be appreciated.


from flask import Flask, g, render_template, flash, redirect, url_for
from flask.ext.bcrypt import check_password_hash
from flask.ext.login import (LoginManager, login_user,
                             logout_user, login_required, current_user)

import forms
import models

DEBUG = True
PORT = 8000
HOST = ''

app = Flask(__name__)
app.secret_key = 'youdontknowmysecretkey'

login_manager = LoginManager()
login_manager.login_view = 'login'

def load_user(userid):
      return models.User.get(models.User.id == userid)
  except models.DoesNotExist:
      return None

def before_request():
  """Connect to the database before each request."""
  g.db = models.DATABASE
  g.user = current_user

def after_request(response):
  """Close the database connection after each request."""
  return response

@app.route('/register', methods=('GET', 'POST'))
def register():
  form = forms.RegisterForm()
  if form.validate_on_submit():
      flash("Yay, you registered!", "success")
          email = form.email.data,
          password = form.password.data
      return redirect(url_for('index'))
  return render_template('register.html', form=form)

@app.route('/login', methods=('GET', 'POST'))
def login():
  form = forms.LoginForm()
  if form.validate_on_submit():
        user = models.User.get(models.User.email == form.email.data)
    except models.DoesNotExist:
        flash("Email is incompatible", "error")
        if check_password_hash(user.password, form.password.data):
            flash("You are logged in", "success")
            return redirect(url_for('index'))
            flash("Password does not match", "error")
  return render_template('login.html', form=form)

def logout():
    flash("You've been logged out! Come back soon!", "success")
    return redirect(url_for('index'))

@app.route('/taco', methods=('GET','POST'))
def taco():
    form = forms.TacoForm()
    if form.validate_on_submit():
        models.Taco.create(user = g.user._get_current_object(),
                           protein = form.protein.data,
                           shell = form.shell.data,
                           cheese = form.cheese.data,
                           extras = form.extras.data.strip()
        flash("Your taco has been added!!", "success")
        return redirect(url_for('index'))
    return render_template('taco.html', form=form)

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

if __name__== '__main__':
    with models.DATABASE.transaction():
          email = 'billy@example.com',
          password = 'password'
  except ValueError:
  #app.run(debug=DEBUG, host=HOST, port=PORT)

1 Answer

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Without seeing your other files, I can't find anything that would be failing in the code challenge. When I put your code into my tester, with known-good versions of the other files, it passes. What are your other files like? Are you submitting them all into the code challenge?

Nthulane Makgato
Nthulane Makgato
Courses Plus Student 19,602 Points

I'm so embarrassed. I thought that all they wanted want tacocat.py.

I just pasted them and it works. Thanks!