title: How to store WTForm Form in session in Flask?
body: <p>I need to store the result of a form in the session, but I keep getting TypeError: XXX is not JSON serializable for datetimes and Decimal fields.  What is the right way to persist the form data between requests? </p>
  
  <p>Here's my form: </p>
  
  <pre><code>class GiftRequestForm(Form):
      giftee_name = StringField('Name',
                            [validators.Required(), validators.length(min=4, max=25)])
      giftee_age = IntegerField('Age',
                            [validators.Required(),
                             validators.NumberRange(min=0, message="Age must be greater than 0")])
      giftee_sex = RadioField('Gender',
                          [validators.Required()],
                          choices=[('0', 'Male'), ('1', 'Female')])
      giftee_relationship = StringField('Relationship',
                                    [validators.Required(), validators.length(min=4, max=25)],
                                    description='Fill in the blank: The recipient is my _____.')
      event = StringField('Event',
                      [validators.Required(), validators.length(min=4, max=80)])
      event_date = DateField('Event Date',
                         [validators.Required()],
                         format='%Y-%m-%d',
                         description="Well have it to you at least four days before the event date.")
      budget = DecimalField('Budget $',
                        [validators.Required(),
                         validators.NumberRange(min=0, message="Budget must be greater than 0")])
  </code></pre>
  
  <p>In my view, I just want to do: </p>
  
  <pre><code>form = GiftRequestForm()
  ...
  session['gift_request_form'] = form
  </code></pre>
  
  <p>This doesn't work at all because it doesn't seem like the GiftRequestForm is JSON serializable.  Unfortunately, this doesn't work either: </p>
  
  <pre><code>session['gift_request_form'] = form.data
  </code></pre>
  
  <p>Because an element in my dictionary is a datetime and a Decimal type.  So I always get a TypeError: datetime.date(2015, 9, 2) is not JSON serializable, or something similar for the Decimal field.  </p>
  
  <p>This seems like a standard pattern -- but I'm having alot of difficulty getting it to work.  How should I do this? </p>