Book Image

Building Web Applications with Flask

By : Italo M Campelo Maia, Jack Stouffer, Gareth Dwyer, Italo Maia
Book Image

Building Web Applications with Flask

By: Italo M Campelo Maia, Jack Stouffer, Gareth Dwyer, Italo Maia

Overview of this book

Table of Contents (17 chapters)
Building Web Applications with Flask
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Debugging, DebugToolbar, and happiness


When running your Flask project in debug mode (app.debug = True), whenever Flask detects that your code has changed it will restart your application. If the given change breaks your application, Flask will display an error message in the console that is actually very simple to analyze. You start reading from the bottom up until you find the first line that mentions a file you wrote; that's where the error was generated. Now, read from the top down until you find a line telling you exactly what the error was. If this approach is not sufficient and if you need to read a variable value—for example, to better understand what is going on—you may use pdb, the standard Python debugging library, like this:

# coding:utf-8
from flask import Flask

app = Flask(__name__)

@app.route("/")
def index_view(arg=None):
    import pdb; pdb.set_trace()  # @TODO remove me before commit
    return 'Arg is %s' % arg


if __name__ == '__main__':
    app.debug = True
    app...