Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you debug url routing in Flask?

I'm developing a Flask website using Visual Studio 2013's PythonTools, which has its own debugger, and that allows me to step through the initial setup code, up until app.run()

However the code I want to debug is the routing code, like this:

@app.route('/')
def url_index():
     return render_template('index.html') 

I know that function is running because the server does respond with index.html, but if I put a breakpoint on the last line, it'll never get hit.

Is there any way to debug these routing functions? Flask says it comes with a debugger but how do I use it? Will it be compatible with Visual Studio?

like image 279
Migwell Avatar asked Mar 15 '14 02:03

Migwell


1 Answers

For the Flask debugger, you can set app.debug to True:

app.debug = True

or

app.run(debug=True)

And then:

@app.route('/')
def index():
   raise
   return render_template('index.html') 

And then you can debug the function with the Flask debugger in your browser.

like image 161
atupal Avatar answered Sep 26 '22 20:09

atupal