Use first_or_404 method from flask-sqlachemy.