Home How to modify redirect in django middleware
Reply: 0

How to modify redirect in django middleware

Daniel Wu
1#
Daniel Wu Published in 2018-02-13 03:17:29Z

I have a requirement to convert http to https if the redirect (HttpResponseRedirectBase) happens in django. So I'd like to write a middleware to handle that. I have put the middleware in the top of the middleware list, hope that's correct.I have used the following sample code. But when redirect happens, the url is not the full url, but relative url. So I don't know how to overwrite the url or schema(http or https). I have thought I could replace the http to https in the response, but the content of the response is also empty. So what should I do?

class RedirectFilter(object):
    def process_response(self, request,response):
        print 1111111111111
        print response.status_code
        print request.path
        print response.__class__.__name__
        if isinstance(response,HttpResponseRedirectBase):
            print response.url
            print response.content
        return response
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.306265 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO