title: Flask WTF 'StringField' object has no attribute 'translate'
body: <p>I am relatively new to Python, and I've been following the <a href="http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world" rel="noreferrer">Miguel Grinberg Flask Mega-Tutorial</a>.</p>
  
  <p>I have a very simple form which, when I try to submit, I receive the following error:</p>
  
  <blockquote>
    <p>AttributeError: 'StringField' object has no attribute 'translate'</p>
  </blockquote>
  
  <p>Here is the form:</p>
  
  <pre><code>from flask.ext.wtf import Form
  from wtforms import StringField
  from wtforms.validators import DataRequired
  
  
  class CreateSubjectForm(Form):
      name = StringField('name', validators=[DataRequired()])
  </code></pre>
  
  <p>And <code>views.py</code>:</p>
  
  <pre><code>@app.route('/create_subject', methods=['GET', 'POST'])
  def create_subject():
      form = CreateSubjectForm()
      if form.validate_on_submit():
          subject = Subject(name=form.name)
          db.session.add(subject)
          db.session.commit()
      return render_template('create_subject.html',
                             title='Create Subject',
                             form=form)
  </code></pre>
  
  <p>My template is as follows:</p>
  
  <pre><code>{% extends "base.html" %}
  
  {% block content %}
      &lt;h2&gt;Create Subject&lt;/h2&gt;
      &lt;form action="" method="post" name="create_subject"&gt;
          {{ form.hidden_tag() }}
          &lt;div class="form-control-label"&gt;Name: &lt;/div&gt;
          &lt;div class="form-control"&gt;{{ form.name(size=45) }}&lt;/div&gt;
          &lt;input type="submit" value="Create"&gt;
      &lt;/form&gt;
  {% endblock %}
  </code></pre>
  
  <p>I have been unable to solve this problem, but here is what I have looked at.</p>
  
  <p>One concern arose from the fact that PyCharm tells me that it cannot find <code>wtf</code> in <code>flask.ext</code> in the line <code>from flask.ext.wtf import Form</code>.  I am using Python 2.7.  From research it appears that this is the correct way to import for 2.7.  I tried changing it to <code>from flask_wtf import Form</code> and the PyCharm error goes away, but the behaviour is the same.</p>
  
  <p>From the traceback I thought it looked like something has gone wrong with versions and packages.  I double check I had everything installed with <code>pip.install</code> and it appears I do - here is <code>pip.freeze</code> from the virtual environment:</p>
  
  <pre><code>Babel==2.2.0
  blinker==1.4
  coverage==4.0.3
  decorator==4.0.9
  Flask==0.10.1
  Flask-Babel==0.9
  Flask-Login==0.3.2
  Flask-Mail==0.9.1
  Flask-OpenID==1.2.5
  Flask-SQLAlchemy==2.1
  Flask-WhooshAlchemy==0.56
  Flask-WTF==0.12
  flipflop==1.0
  guess-language==0.2
  itsdangerous==0.24
  Jinja2==2.8
  MarkupSafe==0.23
  pbr==1.8.1
  PyMySQL==0.7.2
  python-openid==2.2.5
  pytz==2016.3
  six==1.10.0
  speaklater==1.3
  SQLAlchemy==1.0.12
  sqlalchemy-migrate==0.10.0
  sqlparse==0.1.19
  Tempita==0.5.2
  Werkzeug==0.11.5
  Whoosh==2.7.3
  WTForms==2.1
  </code></pre>
  
  <p>And here is the traceback:</p>
  
  <pre><code>&gt; Traceback (most recent call last):   File
  &gt; "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\flask\app.py",
  &gt; line 1836, in __call__
  &gt;     return self.wsgi_app(environ, start_response)   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\flask\app.py",
  &gt; line 1820, in wsgi_app
  &gt;     response = self.make_response(self.handle_exception(e))   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\flask\app.py",
  &gt; line 1403, in handle_exception
  &gt;     reraise(exc_type, exc_value, tb)   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\flask\app.py",
  &gt; line 1817, in wsgi_app
  &gt;     response = self.full_dispatch_request()   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\flask\app.py",
  &gt; line 1477, in full_dispatch_request
  &gt;     rv = self.handle_user_exception(e)   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\flask\app.py",
  &gt; line 1381, in handle_user_exception
  &gt;     reraise(exc_type, exc_value, tb)   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\flask\app.py",
  &gt; line 1475, in full_dispatch_request
  &gt;     rv = self.dispatch_request()   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\flask\app.py",
  &gt; line 1461, in dispatch_request
  &gt;     return self.view_functions[rule.endpoint](**req.view_args)   File "C:\Users\timni\onedrive\dev\studyplanner\app\views.py", line 24, in
  &gt; create_subject
  &gt;     db.session.commit()   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\sqlalchemy\orm\scoping.py",
  &gt; line 157, in do
  &gt;     return getattr(self.registry(), name)(*args, **kwargs)   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\sqlalchemy\orm\session.py",
  &gt; line 801, in commit
  &gt;     self.transaction.commit()   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\sqlalchemy\orm\session.py",
  &gt; line 392, in commit
  &gt;     self._prepare_impl()   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\sqlalchemy\orm\session.py",
  &gt; line 372, in _prepare_impl
  &gt;     self.session.flush()   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\sqlalchemy\orm\session.py",
  &gt; line 2019, in flush
  &gt;     self._flush(objects)   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\sqlalchemy\orm\session.py",
  &gt; line 2137, in _flush
  &gt;     transaction.rollback(_capture_exception=True)   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\sqlalchemy\util\langhelpers.py",
  &gt; line 60, in __exit__
  &gt;     compat.reraise(exc_type, exc_value, exc_tb)   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\sqlalchemy\orm\session.py",
  &gt; line 2101, in _flush
  &gt;     flush_context.execute()   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\sqlalchemy\orm\unitofwork.py",
  &gt; line 373, in execute
  &gt;     rec.execute(self)   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\sqlalchemy\orm\unitofwork.py",
  &gt; line 532, in execute
  &gt;     uow   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\sqlalchemy\orm\persistence.py",
  &gt; line 174, in save_obj
  &gt;     mapper, table, insert)   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\sqlalchemy\orm\persistence.py",
  &gt; line 800, in _emit_insert_statements
  &gt;     execute(statement, params)   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\sqlalchemy\engine\base.py",
  &gt; line 914, in execute
  &gt;     return meth(self, multiparams, params)   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\sqlalchemy\sql\elements.py",
  &gt; line 323, in _execute_on_connection
  &gt;     return connection._execute_clauseelement(self, multiparams, params)   File
  &gt; "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\sqlalchemy\engine\base.py",
  &gt; line 1010, in _execute_clauseelement
  &gt;     compiled_sql, distilled_params   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\sqlalchemy\engine\base.py",
  &gt; line 1146, in _execute_context
  &gt;     context)   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\sqlalchemy\engine\base.py",
  &gt; line 1344, in _handle_dbapi_exception
  &gt;     util.reraise(*exc_info)   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\sqlalchemy\engine\base.py",
  &gt; line 1139, in _execute_context
  &gt;     context)   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\sqlalchemy\engine\default.py",
  &gt; line 450, in do_execute
  &gt;     cursor.execute(statement, parameters)   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\pymysql\cursors.py",
  &gt; line 156, in execute
  &gt;     query = self.mogrify(query, args)   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\pymysql\cursors.py",
  &gt; line 135, in mogrify
  &gt;     query = query % self._escape_args(args, conn)   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\pymysql\cursors.py",
  &gt; line 115, in _escape_args
  &gt;     return dict((key, conn.escape(val)) for (key, val) in args.items())   File
  &gt; "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\pymysql\cursors.py",
  &gt; line 115, in &lt;genexpr&gt;
  &gt;     return dict((key, conn.escape(val)) for (key, val) in args.items())   File
  &gt; "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\pymysql\connections.py",
  &gt; line 781, in escape
  &gt;     return escape_item(obj, self.charset, mapping=mapping)   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\pymysql\converters.py",
  &gt; line 26, in escape_item
  &gt;     val = encoder(val, mapping)   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\pymysql\converters.py",
  &gt; line 109, in escape_unicode
  &gt;     return u"'%s'" % _escape_unicode(value)   File "C:\Users\timni\onedrive\dev\studyplanner\venv\lib\site-packages\pymysql\converters.py",
  &gt; line 72, in _escape_unicode
  &gt;     return value.translate(_escape_table) AttributeError: 'StringField' object has no attribute 'translate'
  </code></pre>
  
  <p>So at this point I am stumped.  Any help will be very greatly appreciated.  Thank you.</p>