Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force https with HyperlinkedModelSerializer?

I'm using the REST-framework for for API, and relationships to a HyperlinkModelSerializer are represented by a url that uses http. Is there any way to force this to return a link with https?

like image 343
echolocation Avatar asked Mar 05 '15 15:03

echolocation


1 Answers

This might be an environment issue. In my case (on Heroku) I needed the production setting:

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

This is because internally the gunicorn instance is actually being connected to using http, you need to tell Django that there is a secure proxy in front of it. Pretty obvious once I stopped to think about it.

Interestingly enough all the other url reverses on the site work fine, just the DRF ones were broken, which was the confusing part.

like image 151
Rob Osborne Avatar answered Oct 29 '22 20:10

Rob Osborne