0

I have send a post request from a flutter app using dio in the code below


Map<String, String> getData() {
    return {
      "firstname": firstname.value,
      "lastname": lastname.value,
      "phonenumber": phoneNumber.value,
      "password": password.value,
      "accounttype": accounttype.value
    };
  }

  void signup(context) async {
    Dio dio = Dio();
    final response = await dio.post(
      'http://192.168.0.101:8000/signup/',
      data: getData(),
    );
    debugPrint(response.toString());
  }

and tried to print it in django from the code below

from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt

@csrf_exempt
def signup(request):
    if request.method == 'POST':
        print(request.POST)
        return HttpResponse('Hello, world!')

I get an empty dictionary when it is printed.

2 Answers2

0

So instead of accessing the data from request.POST you need to access it from request.data as said in below post

Django & TastyPie: request.POST is empty

0

try printing like

@csrf_exempt
def signup(request):
    if request.method == 'POST':
        print(request.data)
        return HttpResponse('Hello, world!')
Dhruv Patel
  • 163
  • 5