How to obtain Flask request JSON data as dictionary? How to obtain Flask request JSON data as dictionary? flask flask

How to obtain Flask request JSON data as dictionary?


The data is being put into request.json because of the mimetype of the request. I believe you are looking for get_json.

@app.route('/projects/<name>', methods=['GET', 'POST'])def projects(name=None):    req_json = request.get_json()    print(req_json['ajax'])    if name:        project = db.getProject(name)        form = ProjectForm(project)        if req_json['ajax']:            return render_template("myform.html", form=form)        return render_template("projectView.html", form=form)    return render_template("projects.html")

I do not have access to my dev machine at the moment so I haven't tested this, but it should work from my understanding of the docs.