Fix Typo

Dang, we put ToDo in the string response instead of Todo. Let’s fix that, while showing how the Run Tool window makes it easy to jump to run-time errors.

Source for this step View video/audio walkthrough

Steps

  1. In app.py, change the show_todo return value to the following:

    return 'Todo {todo_id}'.format(todo_id=xxxtodo_id)
    
  2. Close the editor tab for app.py.

  3. In your browser, click the links until you click on First Todo, which should produce an error.

  4. In PyCharm, find the last line in the traceback:

    File "/Users/pauleveritt/projects/pycharm/epc2016/epc_tutorial/app.py", line 18, in show_todo
    
  5. In the traceback, click on the blue-underlined filename to jump to line 18 in that file.

  6. Change `xxxtodo_id to todo_id.

  7. Reload the web page.

  8. Our app.py file should match the following:

    app.py in Fix Typo
    from flask import Flask
    
    app = Flask(__name__)
    
    
    @app.route('/')
    def home_page():
        return 'Hello World! <a href="/todo/">Todos</a>'
    
    
    @app.route('/todo/')
    def list_todos():
        return 'Todo List <a href="/todo/1">First Todo</a>'
    
    
    @app.route('/todo/<todo_id>')
    def show_todo(todo_id):
        return 'Todo {todo_id}'.format(todo_id=todo_id)
    
    if __name__ == '__main__':
        app.run(debug=True)
    

Analysis

In this short task we saw primarily how the tool window works.

  • Jump to errors. The Run Tool window helps by providing clickable links on exceptions, allowing you to easily jump to the line of an error, opening the file if necessary.

Extra Credit

  1. Can the Run Tool’s parsing of output cause problems?
  2. If your error is a SyntaxError, or a global name error, what happens?