AssertionError: `HyperlinkedIdentityField` requires the request in the serializer context

后端 未结 7 1889
陌清茗
陌清茗 2021-01-31 03:22

I want to create a many-to-many relationship where one person can be in many clubs and one club can have many persons. I added the models.py and

7条回答
  •  不知归路
    2021-01-31 04:19

    You can simply pass None to 'request' key in context in situations where you just need the relative URL, e.g; testing a serializer in command line.

    serializer = YourModelSerializer(modelInstance_or_obj, context={'request': None})
    

提交回复
热议问题