我正在 python Flask 中创建一条路线,它将作为其余 api 来注册用户。当我尝试在 POST 方法中获取通过邮递员传递的 json 数据时,出现错误TypeError: 'NoneType' object is not subscriptable
我来自邮递员的请求:
http://127.0.0.1:5000
/register 原始输入:{"username":"alok","password":"1234"}
我的路线和功能:
@app.route('/register', methods=['GET', 'POST'])
def signup_user():
data = request.get_json()
return data['username']
Run Code Online (Sandbox Code Playgroud)
据我所知,上述函数应该返回:“ alok ”
但我收到错误:TypeError: 'NoneType' object is not subscriptable
任何帮助将不胜感激