Django REST Swagger HTTPS requests

Viewed 4349

How configure django-rest-swagger to get a HTTPS requests?

upd: SSL cert is present and ALL app working with it, but swagger make a http requests.

5 Answers

Put url='https://your_server_address/', in get_schema_view function in urls.

But swagger now only works on https, if you want to work on both http and https you can handle this through env variables.

All the above solutions didn't work for me, so i did something HORRIBLE that worked:

Edited drf_yasg/openapi.py Line 260

From:

self.schemes = [url.scheme]

To:

self.schemes = ["https"]

Obviously you should not do this because the next time someone installs requirements this change will be lost. But it helped me to get the documentation working on my server.

@zaidfazil's answer almost worked for me. I had to add

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

to my django settings but then I had to add

proxy_set_header X-Forwarded-Proto https;

instead of:

proxy_set_header  X-Forwarded-Protocol  $scheme;

inside nginx's location block that serves the django app.

Related