Flask tourist attractions project, help needed

https://www.codecademy.com/paths/build-python-web-apps-flask/tracks/introduction-to-flask/modules/flask-templates-and-forms/projects/tourist-attractions-app

hi im stuck on task 10 on this project, i keep getting Value error when i replace the none values with my code.

my attempt is:

  if request.method == "POST":
    [(name, value)] = request.form.items()

error:

ValueError: not enough values to unpack (expected 1, got 0)

help appreciated, i have no clue how to proceed from here

gist of the code Codecademy export · GitHub

1 Like

Hi,

A little experimentation with the object types your dealing with in the terminal can shed light on this:

>>> test = {1:"Pita",2:"Baguette"}
>>> test.items()
dict_items([(1, 'Pita'), (2, 'Baguette')])
>>> (key,value) = test.items()
>>> key
(1, 'Pita')
>>> value
(2, 'Baguette')
>>> [key,value] = test.items()
>>> key
(1, 'Pita')
>>> value
(2, 'Baguette')
>>> [(key,value)] = test.items()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: too many values to unpack (expected 1)
1 Like

but im getting a “not enough values to unpack” error, also the [(key, value)] is what was provided, i did not write that down myself

i still get the same error when using [key, value] and key, value instead

Try printing request.form.items() and you’ll get feedback in your terminal as to the format (and how to unpack it if you so wish).

Meanwhile I’ll look into the instructions to see if it was an incorrect direction.

how do you view the terminal in the online ide?

Hi,

I’ve never really done flask on the online ide. I highly recommend copying all the file assets and working on this locally, as it’ll give you a better idea for how the workflow with flask is:

  • text editor
  • terminal running flask server
  • browser
  • terminal for other tasks (like ssh’ing into a remote server)

(2 monitors are very useful/comfortable in this setup)

You’ll get much better debugging feedback which will help you get more comfortable. Flask has a very solid debug=True feature that gives you detailed error messages that you can then inquire about online or in documentation.

And best of all, it’s not hard to get set up quickly. I do recommend you use venv though if you’re going to do this.

hello, ive got it all into pycharm but when i run the program, it starts the server but i get a blank screen. none of my project is showing up

i just get this everytime i try refresh the page, no errors

127.0.0.1 - - [08/Feb/2021 22:19:26] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [08/Feb/2021 22:19:26] "GET /favicon.ico HTTP/1.1" 200 -
127.0.0.1 - - [08/Feb/2021 22:20:09] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [08/Feb/2021 22:20:09] "GET /favicon.ico HTTP/1.1" 200 -
127.0.0.1 - - [08/Feb/2021 22:20:10] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [08/Feb/2021 22:20:10] "GET /favicon.ico HTTP/1.1" 200 -
127.0.0.1 - - [08/Feb/2021 22:20:10] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [08/Feb/2021 22:20:10] "GET /favicon.ico HTTP/1.1" 200 -

nevermind, i am supposed to visit /tovisit to even see anything haha, mybad

hi, so ive printed the dict out and it looks like im getting a raw object

print(request.form.items())
<generator object MultiDict.items at 0x03D25680>

im still unsure what to do, do you have any ideas?

I also highly recommend Corey Schafer’s mega tutorial (Python Flask Tutorial: Full-Featured Web App Part 1 - Getting Started - YouTube) as well as Miguel Grinberg’s who wrote the O’Reilly book on flask (Flask Webcast #1: Intro to Flask - YouTube)

Particularly useful is how they deal with database considerations (like migrations) and deployment.

More info on generator objects: