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 trialTrenton Taylor
Courses Plus Student 159 PointsIndention Error?
When I attempt to use the console to run python app.py it sends me an error saying I have an indention error with line 61, please help!
Here is the error:
treehouse:~/workspace$ python app.py
File "app.py", line 62
models.initialize()
^
IndentationError: expected an indented block
Here is the app.py file:
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 = 'b3478tohfre87fvsd87fqw78nf378nc~!'
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.DosNotExist:
return None
@app.before_request
def before_request():
g.db = models.DATABASE
g.db.connect()
@app.after_request
def after_request(responce):
g.db.close()
return responce
@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()
models.User.create_user(
username='trent',
email='taylor@coldcodr.com',
password='password',
admin=True
)
app.run(debug=DEBUG, host=HOST, port=PORT)
1 Answer
Samuel Webb
25,370 PointsThe indentation in your final if
statement is off. Fix the indentation in the following block of code:
if __name__ == '__main__':
models.initialize()
models.User.create_user(
username='trent',
email='taylor@coldcodr.com',
password='password',
admin=True
)
edit:
Also make sure this line has the proper indentation:
app.run(debug=DEBUG, host=HOST, port=PORT)
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 Pointsapp.run
is supposed to be indented one level as well so that it belongs to theif
statement.Samuel Webb
25,370 PointsSamuel Webb
25,370 PointsEdited the answer.
Trenton Taylor
Courses Plus Student 159 PointsTrenton Taylor
Courses Plus Student 159 PointsFixed! Thanks. Now, can you tell me how to start the app/server so that I can preview my work
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsTrenton,
Are you still having an issue with running it?