[Tourist Attractions] Build Python Web Apps with Flask - Step 17



I am having difficulty with this project, specifically task 17 - Looping through the category radio field buttons. When I follow the instructions given I get ValueError: too many values to unpack (expected 2).

Could somebody please tell me how to share code here so that I may be more specific with my question (didn’t wish to take a screenshot as I know this isn’t helpful).


Screen Shot 2020-11-14 at 1.47.25 PM press the </> button and paste your code in between the tick marks.

1 Like

Thanks, here is the app route which is being referred to in the error:

@app.route("/<category>", methods=["GET", "POST"])
def locations(category):
  locations = visit.get_list_by_category(category)
  ## Check the request for form data and process
  for k, v in request.form.items():
    n = k
    val = v
  if request.method == "POST":
    [(name, action)] = [(n, val)]

    if action == UP_ACTION:
    elif action == DEL_ACTION:
  ## Return the main template with variables
  return render_template('locations.html', category=category, categories=categories, locations=locations, add_location=AddLocationForm())

and here is my HTML

          <td>{{ add_location.name.label }}</td> <!-- insert location name label here -->
          <td>{{ add_location.description.label }}</td> <!-- insert location description label here -->
          <td>{{ add_location.category.label }}</td> <!-- insert location category label here -->
          <td>{{ add_location.name() }}</td> <!-- insert add_location name here -->
          <td>{{ add_location.description() }}</td> <!-- insert add_location description here -->
            <!-- begin for loop here -->
            {% for button in add_location.category %}
              <div>{{ button }}{{ button.label }}</div> <!-- insert button here -->
            <!-- end for loop here -->
            {% endfor %}


Finally here is my AddLocationForm

class AddLocationForm(FieldsRequiredForm):
  name = StringField("Location Name", validators=[DataRequired()])
  description = TextAreaField("Location Description", validators=[DataRequired()])
  category = RadioField("Category", choices=[categories])
  submit = SubmitField("Add Location")

Apologies if I’ve left something important out here. Just coming back to this from yesterday and trying to make sense of it all again.



Sorry, can you also copy/paste the exact error message? I suspect it has to do with for k, v in request.form.items() since that’s the only place I see anything being unpacked. In which case you can try to debug by printing request.form.items() and seeing where that trail of crumbs goes. (But this is only hypothetically if this is where the error is).

No problem

It seems like the problem may be in line 71 in locations.html.

This suggests that add_location.category is not a simple list and that you need to unpack it in two values:


{% for button, mystery_value in add_location.category %}

I’m not sure that this was the intended format of your add_location.category but I think it’s the nature of the error.

Hi, I don’t know if you have resolved the issue or not but
category = RadioField(“Category”, choices=[categories])
This should be
category = RadioField(“Category”, choices=categories)
categories is already a list of tuples and what you had was a list of list that is why that issue might be there.


1 Like