Is there an easy way to modify the links out-of-the-box for viewsets and routers?
For example, in urls.py:
from rest_framework import viewsets, routers
...
class Activity_TypeViewSet(viewsets.ModelViewSet):
model = Activity_Type
...
router.register(r'activity_types', Activity_TypeViewSet)
...
url(r'^', include(router.urls)),
This sets up url structure like:
{"activity_types": "http://odd.quantdevgroup.com/activity_types/"}
The question comes down to how easy it is to make the link:
{"activity_types": "**https**://odd.quantdevgroup.com/activity_types/"}
If I deactivated http/ port 80 and only allowed https/ port 443 then my app requires manually adding https to the link after it fails to open http (because I disabled port 80).
DRF reverse uses
request.build_absolute_uri(url)
to generate urls which will build URLs "using the server variables available in this request.", so if the request is http, generated URLs will be HTTP and same thing for HTTPS.If your django app running behind a reverse proxy, then you need to configure SECURE_PROXY_SSL_HEADER setting.
However, you have to be really careful when setting this:
For nginx, you can set
X-Forwarded-Proto
header using this configuration: