Just as i posted this question, i found the answer:
I needed to change
'Title': request.get('Title', ""),
to
'Title': request.json.get('Title', ""),
Вопрос
When i make a POST request to my server, i get a 500 ERROR with comment:
AttributeError: 'Request' object has no attribute 'get'
This is my server:
@app.route('/api/entries', methods = ['POST'])
def create_entry():
if not request.json:
abort(400)
entry = {
'id': entries[-1]['id'] + 1,
'Title': request.get('Title', ""),
'Description': request.get('Description', ""),
'Info': request.get('Info', "")
}
entries.append(entry)
return jsonify( { 'entry': entry } ), 201
here is also my entries array:
entries = [
{
'id': 1,
'Title': 'baradum',
'Description': 'desc 1',
'Info': 'info1',
},
{
'id': 2,
'Title': 'jasd',
'Description': 'desc 2',
'Info': 'info 2',
}
]
What causes the problem?
Решение
Just as i posted this question, i found the answer:
I needed to change
'Title': request.get('Title', ""),
to
'Title': request.json.get('Title', ""),