简体   繁体   中英

In a Django Rest Framework 3 Serializer how do I access the request object?

In a Django Rest Framework 3 Serializer how do I access the request object?

For example I want to get META['HTTP_AUTHORIZATION'] ie..

def create(self, validated_data):
    self.request.DATA['key']
    self.request.META['HTTP_AUTHORIZATION']
    return Snippet.objects.create(**validated_data)

But above gives an error that request is not available

经过对其他有兴趣的人的反复试验之后,

self.context['request']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM