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 Flask Basics Character Builder Forms

Sean May
Sean May
9,145 Points

PDB does not have Request as an available option

I've been doing pretty well following the tasks so far, but I'm having an issue here, and it appears to be with PDB. Here's my app.py:

from flask import Flask, render_template, redirect, url_for
app = Flask(__name__)


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

@app.route('/save', methods=['POST'])
def save():
    import pdb; pdb.set_trace()
    return redirect(url_for('index'))

app.run(debug=True, host='0.0.0.0', port=7999)

when I run the page and try to do request.form, I get:

*** NameError: name 'request' is not defined

Weird, huh?

When I run dir(pdb), I get:

['Pdb', 'Restart', 'TESTCMD', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_rstr', '_usage', 'bdb', 'cmd', 'code', 'dis', 'find_function', 'getsourcelines', 'glob', 'help', 'inspect', 'lasti2lineno', 'line_prefix', 'linecache', 'main', 'os', 'pm', 'post_mortem', 'pprint', 're', 'run', 'runcall', 'runctx', 'runeval', 'set_trace', 'signal', 'sys', 'test', 'traceback']

...which is not at all the number of options Kenneth has in Workspaces. I'm running Python 3, and as far as I know everything should be up to date, but I can't see request as a part of PDB. What am I missing?

1 Answer

Sean May
Sean May
9,145 Points

Sorry, figured it out myself after digging a bit. I didn't import request at the top.

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hi Sean,

I have changed your comment into a question, so we are able to mark it as best answer and close the thread.

Good effort!

Vittorio

Anthony Attard
Anthony Attard
43,915 Points

Vittorio Somaschini, I assume you mean "into a answer", not "into a question". Please edit it if you can so students in future are not confused. Thanks.