format issue when saving captured data with request.POST

Viewed 31

The data is being captured, however when saving to the database it is being saved with quotes and square brackets.

def create_flow_and_phases(request):


    data = {
        "name": request.POST['new_flow_name'],
        "description": request.POST['flow_description'],
        "category": request.POST['select_category'],
        "precedents": [request.POST['precedent_list']],
        "users": [1],
        "phases": ''
    }

    # Making a POST request to save flow_and_phases
    url = API_HOST + "/api/flows/save_flow_and_phases/"

    answer = requests.post(url, data=data, headers={'Authorization': 'Token ' + request.session['user_token']})

    if not answer.ok:
        raise Exception("An error occurred while creating flow.")

Example of data in DB: Name: ['test']

I'm using Django Framework

1 Answers

I needed to pass the data dictionary as a JSON and it worked

answer = requests.post(url, json=data, headers={'Authorization': 'Token ' + request.session['user_token']})
Related