title: Pre-Populate a WTforms in flask, with data from a SQLAlchemy object
body: <p>I am fairly new to flask framework and was creating an edit profile page for a webportal. I am stuck at a point and am unable to autofill a form.</p>
  
  <p>Here is my form class : </p>
  
  <pre><code>class EditProfile(Form):
  
      username = TextField('Username', [Required()])
      email = TextField('Email', [Required()])
      about = TextAreaField('About', [Required()])
      website = TextField('Website', [Required()])
  </code></pre>
  
  <p>This is my function that evaluates the form.</p>
  
  <pre><code>def editprofile(nickname = None):
      if g.fas_user['username'] == nickname  or request.method == 'POST':
          form = EditProfile()
          form_action = url_for('profile.editprofile')
          if request.method == 'POST' and form.validate():
              if form.username.data == nickname : 
                query = EditProfile(form.username.data,
                                   form.email.data,
                                   form.about.data,
                                   form.website.data,
                                   )
                print query #debug
                db.session.add(query)
                db.session.commit()
                flash('User Updated')
                print "added"
              return(url_for('profile.editprofile'))
          return render_template('profile/add.html', form=form,
                                 form_action=form_action, title="Update Profile")
      else:
          return "Unauthorised"
  </code></pre>
  
  <p>And my html template for form is form is :</p>
  
  <pre><code>{% extends "base.html" %}
      {% block title %}
          {{ title }}
      {% endblock %}
      {% block content %}
      {% from "_formhelpers.html" import render_field %}
      &lt;div id="Edit Profile"&gt;
          &lt;h2&gt;{{  title  }}&lt;/h2&gt;
          &lt;form method="post" action="{{ form_action }}"&gt;
              &lt;fieldset&gt;
                  &lt;legend&gt;&lt;/legend&gt;
                  {{ render_field(form.username) }}
                  {{ render_field(form.email)}}
                  {{ render_field(form.about )}}
                  {{ render_field(form.website) }}
              &lt;/fieldset&gt;
          &lt;input type="submit" class="button" value="Save"/&gt;
      &lt;/form&gt;
      &lt;/div&gt;
      {% endblock %}
  </code></pre>
  
  <p><br/></p>
  
  <p>I have an object, of user class. And from that object I want to prefill this form.How can I prepopulate the values in the form. I am trying to implement the edit profile functionality here. </p>