0

I am trying to iterate through GoalHours and GoalNames to get names & hours.

HTML

{% for names, hours in  GoalHours, GoalNames %}
   <input  type="submit" value="{{names}}: {{ hours }}" class="btn" name="remove" required> Hrs 
{% endfor %}

Flask

@blueprint.route('/goals' , methods=['GET', 'POST'])
def goals():
    goal_ = theGoal(str(flask.session['id']))
    goalNames_ = goal_['goalName']
    goalHours_ = goal_['goalHours']
    
    return render_template('/accounts/goals.html', calList = calList, GoalHours = goalHours_, GoalNames = goalNames_)

I keep on getting:

ValueError: too many values to unpack (expected 2)

I tried every web solution from zipping to adding various iter methods to importing zip which gave AttributeError: 'Blueprint' object has no attribute 'jinja_env'. Really appreciate your help

Daniyal dehleh
  • 2,314
  • 2
  • 7
  • 22
  • 1
    This question is answered in the article above. I have tested passing zip in template variable and use it in Jinja2 as you would in Python works. So just pass zip=zip on your app and zip(A,B) on Jinja2 – Prayson W. Daniel Jan 14 '21 at 18:07
  • 1
    Gotcha! Yeah that did the job. I saw that answer in the post too & tried it out but since it only had 1 vote (until I upvoted it too) & it didn't work as I didn't know if I should add `zip(a,b)` as the verified answers didn't show or only showed for one (A or B) i didn't know I had to add for both. Thanks for your comprehensive answer! – Daniyal dehleh Jan 14 '21 at 18:22

0 Answers0