how to access POST data inside tastypie custom Authentication

前端 未结 4 1274
北荒
北荒 2021-01-02 04:58

I\'m trying to write custom Authentication in tastypie. Basically, I want to do the authentication using the post parameters and I don\'t want to use the django auth at all,

4条回答
  •  灰色年华
    2021-01-02 05:19

    I've created a utility method that works well for me. Though I am not sure how this affects the underlying parts of Django, it works:

    import io
    
    
    def copy_body(request):
        data = getattr(request, '_body', request.body)
        request._body = data
        request._stream = io.BytesIO(data)
        request._files = None
        return data
    

    I use it in a middleware to add a JSON attribute to request: https://gist.github.com/antonagestam/9add2d69783287025907

提交回复
热议问题