skip to Main Content

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

Answers


  1. Chosen as BEST ANSWER

    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


  2. try printing like

    @csrf_exempt
    def signup(request):
        if request.method == 'POST':
            print(request.data)
            return HttpResponse('Hello, world!')
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search