Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'NoneType' object has no attribute 'filter' #57

Open
erickrocha opened this issue Apr 23, 2020 · 0 comments
Open

'NoneType' object has no attribute 'filter' #57

erickrocha opened this issue Apr 23, 2020 · 0 comments

Comments

@erickrocha
Copy link

erickrocha commented Apr 23, 2020

Flask-MongoAlchemy==0.7.2

from flask_mongoalchemy import Document
my class
class User(Document):
id = db.StringField()
email = db.StringField()
password = db.StringField()
name = db.StringField()

`from flask import request, make_response, jsonify, current_app
from time import time
from app.models import User
from app.security import bp

@bp.route('/freeman/login', methods=['POST'])
def login():
email = request.json['email']
password = request.json['password']
user = User.query.filter(User.email == email)
if user is None or not user.check_password(password):
return make_response(jsonify({'error': 'Unauthorized access'}), 401)
expires_in = time() + current_app['EXPIRATION_TIME']
secret_key = current_app['SECRET_KEY']
token = user.login(secret_key, expires_in)
return make_response(jsonify({'type': 'bearer', 'token': token, 'expireIn': expires_in}), 200)

@bp.route('/freeman/api/users', methods=['GET'])
def get_users():
users = User.query.all()
return make_response(jsonify({'users': users}), 200)`

I debugged and I don know what's happens, but my query object has no instance and looking the documentation it's OK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant