convert requests.models.Response to Django HttpResponse
<p>In my Django project, I need to get/post some data to a third-party url in my view, and redirect to the web page it provides. For example, I can simply do something like </p>

<pre><code>class TestView(TemplateView):
    def get(self, request, *args, **kwargs):
        data = {
            'order_id': 88888,
            'subject': 'haha',
            'rn_check': 'F',
            'app_pay': 'T',
        }
        url = 'http://some-third-party-api-url?order_id=88888&amp;subject=haha&amp;...'
        return HttpResponseRedirect(url)
</code></pre>

<p>However I want to use this third-party api as a wrapped SDK , like </p>

<pre><code>class TestView(TemplateView):
    def get(self, request, *args, **kwargs):
        from sucre.alipay_sdk.base import Alipay
        from sucre.alipay_sdk import alipay_config
        from django.http import HttpResponse
        alipay = Alipay(alipay_config)
        data = {
            'order_id': 88888,
            'subject': 'haha',
            'rn_check': 'F',
            'app_pay': 'T',
        }
        '''alipay api is wrapped in a sdk'''
        '''and return a requests.models.Response instance'''
        result = alipay.api('pay', data)
        return HttpResponse(result)
</code></pre>

<p>and the api code:</p>

<pre><code>def api(self, service, data):
    ''' some logics here '''
    import requests
    response = requests.get(url, data=data)
    return response
</code></pre>

<p>But seems HttpResponse(result) is not the correct way to convert a requests.models.Response instance to HttpResponse... The layout is bad, and some more encoding issues, etc...Is there a correct way to convert requests response to Django HttpResponse?</p>

<hr>

<p>Updates:</p>

<p>HttpResponse(result) worked, but some css of the page was lost. This might be related with using requests.</p>