Django REST框架不一致

2024-04-19 01:42:14 发布

您现在位置:Python中文网/ 问答频道 /正文

当我从localhost:8000/用户,我得到如下用户:

{
    "username": "iv4ha05k",
    "email": "xxxx@xxx.com",
    "profile": {
        "image": "http://localhost:8000/media/images-4.jpg"
    },
    "pk": 303
},

但是,如果我从django manage shell请求用户数据,数据将如下所示:

{
    "username": "iv4ha05k",
    "email": "xxxx@xxx.com",
    "profile": {
        "image": "/media/images-4.jpg"
    },
    "pk": 303
},

注意图像url是如何被截断的。我在相同的状态下查询相同的数据库,它与迁移或类似的操作无关。我在尝试编写自定义API视图时发现了这个问题。当我查询用户viewset时,它将返回带有完整图像地址的数据。但是,当我尝试编写一个查询用户数据库的自定义API视图时,它将返回带有截断地址的视图。我用的是django的FileSystemStorage,如果这对任何人都有帮助的话。。谢谢。你知道吗


Tags: 数据用户imagecom视图localhostemailusername