【发布时间】:2020-05-16 22:54:30
【问题描述】:
请我在我的 Angular 和 django 项目上需要帮助,当我发出 400 错误响应错误时,项目工作流程如下,用户注册(成功)然后被重定向到一个配置文件表单,然后当我在填写配置文件后尝试发出发布请求时,我得到一个 400 错误,下面是我的代码和错误响应
角度服务.ts
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)
);
}
创建配置文件component.ts
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));
}
}
django 网址
path('profiles', CreateProfileView.as_view(), name='user-profile'),
django 视图
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
如果有人可以帮助我,我会很高兴
【问题讨论】:
标签: django angular django-rest-framework