title: How to change values in Flask session dictionary using forms?
body: <p>I'm writing shopping cart on Flask.</p>
  
  <p>My cart based on session and forming dictionary like this:</p>
  
  <pre><code>[{'qty': 1, 'product_title': 'Post num six', 'product_id': 6}, 
  {'qty': 1, 'product_title': 'Post five', 'product_id': 5}, 
  {'qty': 1, 'product_title': 'Fouth post', 'product_id': 4}]
  </code></pre>
  
  <p>I need to change <em>qty</em> value in <strong>/cart</strong> route for every product in cart:</p>
  
  <pre><code>@app.route('/cart', methods=['GET', 'POST'])
  def shopping_cart():
      page_header = "Cart"
  
      if request.method == 'POST' and 'update_cart' in request.form:                
          for cart_item in session["cart"]:
              cart_item["qty"] += 1 # this is wrong
  
              if cart_item["qty"] &gt; 10:
                  flash(u'Maximum amount (10) products in cart is reached', 'info')
                  cart_item["qty"] = 10
  
          flash(u'update_cart', 'warning')
  
      return render_template('cart/cart.html', page_header=page_header)
  </code></pre>
  
  <p>Here is my <strong>cart.html</strong> template:</p>
  
  <pre><code>...
  {% if session.cart %}
  
  &lt;form action="" method="post"&gt;
      &lt;div class="table-responsive"&gt;
          &lt;table class="table table-hover"&gt;
              &lt;thead&gt;
                  &lt;tr&gt;
                      &lt;th&gt;Name&lt;/th&gt;
                      &lt;th width="100"&gt;Qty&lt;/th&gt;
                  &lt;/tr&gt;
              &lt;/thead&gt;
              &lt;tbody&gt;
              {% for cart_item in session.cart %}
                  &lt;tr&gt;
                      &lt;td&gt;&lt;a href="/post/{{ cart_item.product_id }}"&gt;{{ cart_item.product_title }}&lt;/a&gt;&lt;/td&gt;
  
                      &lt;td&gt;
                          &lt;div class="form-group"&gt;
                              &lt;input class="form-control" type="number" name="change_qty" min="1" max="10" value="{{ cart_item.qty }}"&gt;
                          &lt;/div&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
              {% endfor %}
              &lt;/tbody&gt;
          &lt;/table&gt;
      &lt;/div&gt;
  
      &lt;div class="clearfix"&gt;
          &lt;button type="submit" name="update_cart" class="btn btn-info pull-right"&gt;Update Cart&lt;/button&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  
  {% else %}
      &lt;h2 style="color: red;"&gt;There is no cart session =(&lt;/h2&gt;
  {% endif %}
  </code></pre>
  
  <p>In cart.html  covers all instances in cycle and adds <strong>change_qty</strong> input to change quantity of each product in cart.</p>
  
  <p><strong>The question is:</strong> how i can change quantity of each product in cart?</p>