Release

At three my father carried me, Running from shots and screams. At five I threw stones at the soldiers, When he found out he scolded me. At ten they shot him dead in the street, I saw the blood every…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Django REST always return hyperlink with http proto even if the request is made via https

We always host Django app behind a proxy server(apache or nginx) in production, the connection from your client and the proxy server may be(better be) https. However, between the proxy server and Django app(gunicorn or whatever you’re using) is usually http. So Django thinks that the client is using http, and returns all hyperlink including media link & hyperlink fields using http protocol.

This sometimes is not a big problem, as we can force all http connection to our proxy server to use https like the following.

This may solve the security problem but what if your client does not support http(IOS, WechatApp etc.)?

The best way to solve this is to let Django know the protocol that your client is using.

Now we know the reason behind this, solving the problem becomes trivial.

Use one of Django’s setting

And don’t forget to forward protocol in your proxy server, here is an example in Apache.

Problem solved :)

Add a comment

Related posts:

India to focus on bridging international skills gap

India will look up to the G20 nations to develop an international skills portal to address issues related to global skills gap while deliberating on the gig and platform economy and sustainable…

Canvas Model

The app that our team made is to effectively prevent STDs and help under-educated people to learn more about STDs. During the class, we made a Canvas Model as I attached above. Canvas Model help…

Diet of the future and the challenge for Graphic Designers

The food crisis is predicted to happen in 2050 due to the increase in the world population and our inability to provide enough food. Food producers need to increase 70% of their production at least…