请我在我的angular和django项目上需要帮助,我发出发布请求时遇到400错误的响应错误,项目工作流程如下,用户注册(成功)然后重定向到一份个人资料表格,当我在填写个人资料后尝试发出发布请求时,我得到了400 err,下面是我的代码和d err响应
addProfile(profile: Iprofile): Observable<Iprofile>{
const url = 'http://127.0.0.1:8000/user/profiles';
return this.httpClient.post<Iprofile>(url, profile)
.pipe(
map(response => response),
catchError(this.handleError)
);
}
addUpdateProfile(){
if (this.profile) {
this.dataService.updateProfile(this.profileForm.value)
.subscribe(item => this.profiles.push(this.profileForm.value));
}
else {
this.dataService.addProfile(this.profileForm.value)
.subscribe(item => this.profiles.push(this.profileForm.value));
}
}
path('profiles', CreateProfileView.as_view(), name='user-profile'),
class CreateProfileView(generics.ListCreateAPIView):
queryset = Profile.objects.all()
serializer_class = UserDetailSerializer
错误请求:/ user / profiles [14 / May / 2020 17:07:04]“ POST / user / profiles HTTP / 1.1” 400 46
如果有人能帮助我,b会很高兴
答案 0 :(得分:1)
在documentation中,它表示“如果提供的用于创建对象的请求数据无效,则将返回400 Bad Request响应,并将错误详细信息作为响应的主体。”因此,您发送的个人资料无效。要查看哪个部分不对,请登录正文,或者您可以覆盖并调试CreateApiView
的post方法