Learn Flask - Tourist Attractions Project - Step 10

I’m having trouble with the Tourist Attractions Project for Learn Flask
https://www.codecademy.com/courses/learn-flask/projects/tourist-attractions-app

Step 10 mentions to replace [(None, None)] with request.form.items()

Hence my code is

if request.method == “POST”:
[(name, action)] = request.form.items()

When I click on ‘X’ i get an error message saying
ValueError: not enough values to unpack (expected 1, got 0)

Is this right?

I think this is a type in the instructions (though I haven’t done the exercise). If you get to use the terminal interface with these exercises that’s the first place to troubleshoot.

However, since that might not be the case, I leave you this clue:

>>> test = {"hello": 1, "world": 2}
>>> test.items()
[('world', 2), ('hello', 1)]
>>> (x,y) = test.items()
>>> x
('world', 2)
>>> y
('hello', 1)
>>> [(x,y)] = test.items()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: too many values to unpack

Notice methodology:

  • get error
  • isolate the error data types (dictionaries and the items() method in this case)
  • try to replicate the error
1 Like

Check what you have for the action attribute of the submit button of the add location form.

It should be something like this.

<form class="addform" action="{{ url_for('add_location') }}" method="POST">

1 Like

No, that’s not how the form is presented or set up or how it works