title: Python Flask: AttributeError: 'NoneType' object has no attribute 'count'
body: <p>I'm following a Flask tutorial to do authentication in my app. My user class is like so:</p>
  
  <pre><code>class User(UserMixin, db.Model):  # Here we inherit from two classes
      __tablename__ = 'users'
      id = db.Column(db.Integer, primary_key=True)
      email = db.Column(db.String(64), unique=True, index=True)
      username = db.Column(db.String(64), unique=True, index=True)
      role_id = db.Column(db.Integer, db.ForeignKey('roles.id'))
      password_hash = db.Column(db.String(128))
  
      # Custom property getter
      @property
      def password(self):
          raise AttributeError('password is not a readable attribute')
  
      # Custom property setter
      @password.setter
      def password(self, password):
          self.password_hash = generate_password_hash(password)
  
      def verify_password(self, password):
          return check_password_hash(self.password_hash, password)
  
      def __repr__(self):
          return '&lt;User %r&gt;' % self.username
  </code></pre>
  
  <p>My login route is defined like so:</p>
  
  <pre><code>@auth.route('/login', methods=['GET', 'POST'])
  def login():
      form = LoginForm()
      if form.validate_on_submit:
          # Get a user by email and check password matches hash
          user = User.query.filter_by(email=form.email.data).first()
          if user is not None and user.verify_password(form.password.data):
              login_user(user, form.remember_me.data)
          flash('Invalid username or password')
      return render_template('auth/login.html', form=form)
  </code></pre>
  
  <p>However when I point my browser to the <code>/login</code> endpoint I get the following errors:</p>
  
  <pre><code>File "/Users/kekearif/Documents/Python/FlaskWebDev/flasky/venv/lib/python2.7/site-packages/flask/app.py", line 1994, in __call__
  return self.wsgi_app(environ, start_response)
  File "/Users/kekearif/Documents/Python/FlaskWebDev/flasky/venv/lib/python2.7/site-packages/flask/app.py", line 1985, in wsgi_app
  response = self.handle_exception(e)
  File "/Users/kekearif/Documents/Python/FlaskWebDev/flasky/venv/lib/python2.7/site-packages/flask/app.py", line 1540, in handle_exception
  reraise(exc_type, exc_value, tb)
  File "/Users/kekearif/Documents/Python/FlaskWebDev/flasky/venv/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
  response = self.full_dispatch_request()
  File "/Users/kekearif/Documents/Python/FlaskWebDev/flasky/venv/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
  rv = self.handle_user_exception(e)
  File "/Users/kekearif/Documents/Python/FlaskWebDev/flasky/venv/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
  reraise(exc_type, exc_value, tb)
  File "/Users/kekearif/Documents/Python/FlaskWebDev/flasky/venv/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
  rv = self.dispatch_request()
  File "/Users/kekearif/Documents/Python/FlaskWebDev/flasky/venv/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
  return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/kekearif/Documents/Python/FlaskWebDev/flasky/app/auth/views.py", line 14, in login
  if user is not None and user.verify_password(form.password.data):
  File "/Users/kekearif/Documents/Python/FlaskWebDev/flasky/app/models.py", line 38, in verify_password
  return check_password_hash(self.password_hash, password)
  File "/Users/kekearif/Documents/Python/FlaskWebDev/flasky/venv/lib/python2.7/site-packages/werkzeug/security.py", line 245, in check_password_hash
  if pwhash.count('$') &lt; 2:
  AttributeError: 'NoneType' object has no attribute 'count'
  </code></pre>
  
  <p>Not sure what is happening here. I'm calling the endpoint from a GET (e.g. submit has not been tapped so form.validate_on_submit should be false) and there should be no password check done at all. Any ideas what I am doing wrong?</p>