title: How to correctly redirect/submit POST request from a form (wtforms) to a REST api (flask-restless)?
body: <p>I can't find a proper way to redirect data from submitted form to a REST api.</p>
  
  <p>Currently - like in example below - "POST" method is handled in the view/route (see route "add_person()").</p>
  
  <p>My sample data model (SQLAlchemy-based):</p>
  
  <pre><code>class Person(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      name = db.Column(db.String(20))
  </code></pre>
  
  <p>Form for rendering via html (wtforms-based):</p>
  
  <pre><code>class PersonForm(FlaskForm):
      name = TextField("Person name", validators=[DataRequired()])
  </code></pre>
  
  <p>View/route declaration:</p>
  
  <pre><code>@views.route('add_person', methods=["GET", "POST"])
  def add_person():
      form = PersonForm()
      if request.method == 'POST' and form.validate_on_submit():
          person = Person()
          person.name = form.name.data
          db.session.add(person)
          db.session.commit()
          return redirect(url_for('view.add_person'))
      return render_template('person_add.html', form=form)        
  </code></pre>
  
  <p>HTML template:</p>
  
  <pre><code>&lt;form method="POST" action="/add_person"&gt;
      {{ form.csrf_token }}
      {{ form.name.label }} {{ form.name(size=20) }}
      &lt;input type="submit" value="Submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Now I'd like to delegate database/CRUD related actions to a REST api.</p>
  
  <p>API endpoint generated for a "Person" data model is: "<strong>/api/person</strong>".</p>
  
  <p>If I switch form's "action" from:</p>
  
  <pre><code>"/add_person"
  </code></pre>
  
  <p>to:</p>
  
  <pre><code>"/api/person", 
  </code></pre>
  
  <p>then I'm redirected to the API url, so I guess that's not a proper way of doing that.</p>
  
  <p>I think I still should be using the view/route handling and make a POST api call there instead of persisting the "Person" object. Is this the cleanest solution? How could I approach this? </p>