2

In my django webapp, I have to pass user data param(udp) in a request and return the same in response without modifying it in view.

Request

{
        "mobile": "111111111",
        "udp":[
            { 
                "key": "keyName",
                "value":"valueName"
            },
             { 
                "key": "keyName",
                "value":"valueName"
            },
        ]
    }

Response

{
        "code": "200",
        "message": "success message",
        "response": {
            "data":"user data"
            "udp":[
                    { 
                        "key": "keyName",
                        "value":"valueName"
                    },
                     { 
                        "key": "keyName",
                        "value":"valueName"
                    }
                ]
        }
    }

I thought of acheiving this by writting custom middleware but after accessing request in middleware, View is throwing me error

you cannot access body after reading from request's data stream

Can anyone suggest how this can be implemented? or What will be best approach of doing this in django

user2858738
  • 520
  • 4
  • 15
  • Why are you doing this in middleware and not the view? I think accessing the body in middleware is not advised in Django. – WilsonPena Nov 17 '17 at 19:36
  • Yes, but I need process all request for udp. That's why I wanted to make a common interface that will take care of these things. – user2858738 Nov 17 '17 at 19:39

0 Answers0