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

Could you please tell me the error with my app.py project

This is the error I continiously receive when ever i try to run app.py...

  • Detected change in '/home/treehouse/workspace/models.py', reloading
  • Restarting with stat
  • Debugger is active!
  • Debugger pin code: 254-070-444
    10.120.36.5 - - [06/Feb/2017 21:30:50] "GET /?debugger=yes&cmd=resource&f=ubuntu.ttf HTTP/1.1 " 200 -
    10.120.36.5 - - [06/Feb/2017 21:30:50] "GET /?debugger=yes&cmd=resource&f=console.png HTTP/1. 1" 200 -

This is my code.

from flask import (Flask, g, render_template, flash, redirect, url_for)
from flask.ext.login import LoginManager

import forms
import models

DEBUG = True
PORT = 8000
HOST = '0.0.0.0'

app = Flask(__name__)
app.secret_key = 'as;dklfjpoqwijfl.wajfisjdlfijapwejifpsjadifpoij!'

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

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

@app.before_request
def before_request():
    """Connect to database before each request"""
    g.db = models.DATABASE


@app.after_request
def after_request(response):
    """CLose database connection after each request."""
    g.db.close()
    return response

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

@app.route('/')
def index():
    return 'Hey'


if __name__ == '__main__':
    models.initialize()
    try:
        models.User.create_user(
        username='kennethlove',
        email='kenneth@teamtreehouse.com',
        password='password',
        admin=True
        )
    except ValueError:
        pass

    app.run(debug=DEBUG, host=HOST, port=PORT)

1 Answer

That's probably not an error...

If there is an error, please :point_right: point it out :point_left:

What you are showing now is what Flask prints by default when you have debug=True in the app.run() function.

If this is your first Python course on Flask, I would recommend the Flask Basics course first.

I hope this helps. ~Alex