我在下面的代码中使用dio从flutter应用程序发送了一个帖子请求
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());
}
并尝试在django中从下面的代码打印它
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!')
印刷时我得到一本空字典。
2条答案
按热度按时间afdcj2ne1#
因此,而不是从request.POST访问数据,您需要从www.example.com访问它request.data如下面的帖子所述
Django & TastyPie: request.POST is empty
xienkqul2#
尝试打印类似