django-rest-framework - Django Rest Freamwork:允许对 api 的特定部分进行补丁
问题描述
我希望用户能够创建和编辑配置文件信息,但我在该 api 上也有不应更改的字段是否可以允许修补或放置模型实例的特定部分,或者我将不得不将它们分开
视图.py
@api_view(['GET'])
def current_user(request):
user = request.user
user_details = get_object_or_404(Profile, user=user)
print(user_details)
Profile_serializer = ProfileSerializer(user_details)
return Response({
'profile': Profile_serializer.data,
'id': user.id,
'username' : user.username,
'firstname' : user.first_name,
'lastname' : user.last_name,
'e-mail' : user.email,
'Active': user.is_active,
'Staff': user.is_staff,
'SuperUser': user.is_superuser,
'Last Login': user.last_login,
'Date Joined': user.date_joined,
})
Api(我要更改的部分显然是第一部分,配置文件对象)
{
"profile": {
"bio": "sqdfgq",
"profile_pic": "/media/images/3b8ad2c7b1be2caf24321c852103598a_3GrOBwJ.jpg",
"URL1": "SDFHG",
"URL2": "naah"
},
"id": 1,
"username": "Adel",
"firstname": "Adel",
"lastname": "Bou",
"e-mail": "meh@gmial.com",
"Active": true,
"Staff": true,
"SuperUser": true,
"Last Login": "2021-05-04T09:34:45.476833Z",
"Date Joined": "2021-04-18T10:05:54Z"
}
解决方案
推荐阅读
- javascript - 如何使用 javascript 从模态中获取文本值?
- javascript - 从 Promise 的捕获中添加到现有的 Promises.all 数组
- c# - Entity Framework Core 3.5.1 中的 Linq 查询
- python - 将 XML 转换为 python 字典
- r - R:矢量化在 R6 中设置活动字段
- html - 由于某种原因,标签不会在 css 中旋转
- spring - 使用 Kinesis 启动 Spring Cloud Stream 时出错
- google-apps-script - 将 onEdit 添加到现有功能
- ios - 应用程序重新获得焦点时如何调用函数?
- html - 如何设置引导开关的 CSS 颜色?