0

Based on the description of official website, with following usage:

from flask import jsonify

@app.route('/_get_current_user')
def get_current_user():
    return jsonify(username=g.user.username,
                   email=g.user.email,
                   id=g.user.id)

jsonify can return a json response

{
    "username": "admin",
    "email": "admin@localhost",
    "id": 42
}

Also I came across some usage like this:

@app.route('/token')
@auth.login_required
def get_auth_token():
    token = g.user.generate_auth_token()
     return jsonify({'token': token.decode('ascii')})

based on the debugging, it seems that in this case jsonify returns a str. Not so sure about the usage. Any help on this? Thanks in advance

r-m-n
  • 14,192
  • 4
  • 69
  • 68
Chris Bao
  • 2,418
  • 8
  • 35
  • 62

0 Answers0