1

I have the following dictionary i want to iterate with pyjade:

stations = {'ren': 'RENA', 'hum': 'Hummelvoll'}

In my index.jade i have the following snippet:

each val, index in stations
    li= index + ': ' + val

This raises a

"ValueError: too many values to unpack"

error. The snippet is directly taken from http://jade-lang.com/reference/iteration/

I am sure the dictonary is available to be parsed with jade.

Using "=stations['ren']" renders correctly to "RENA".

When i iterate a tuple or list, the page renders correctly.

Is this a bug, do i need to include something else, or does jade not support the use of dictonaries like the ones i would like to use?

EdChum
  • 376,765
  • 198
  • 813
  • 562
Peter
  • 57
  • 5
  • The iterable returned from a dict is the keys, you should be using the keys to access the items – EdChum Mar 27 '15 at 08:48
  • Dunno about jade but in python the reason would be that you have to write `stations.items()` otherwise you would iterate over the keys only. Guess its a similar issue here. – swenzel Mar 27 '15 at 08:48
  • Sorry I thought this was python code but in fact it's jade which I know nada about, could you try this: `each index in stations li= index + ': ' + stations[index]` I have no idea whether this is valid – EdChum Mar 27 '15 at 08:50
  • I fixed this problem by using the Jinja2 syntax in the jade template. Not the cleanest way to do this but it works very well. – Peter Apr 11 '16 at 20:27

0 Answers0