79094943

Date: 2024-10-16 16:21:07
Score: 0.5
Natty:
Report link

configure SECURE_PROXY_SSL_HEADER like in answer above https://stackoverflow.com/a/72685575/1611526

class BothHttpAndHttpsSchemaGenerator(OpenAPISchemaGenerator):
        def get_schema(self, request=None, public=False):
            schema = super().get_schema(request, public)
            if request.is_secure():
                schema.schemes = ['https']
            else:
                schema.schemes = ['http']
            return schema

then:

schema_view = get_schema_view(
    ...
    generator_class=BothHttpAndHttpsSchemaGenerator,
)

This configuration works for dev and production environments.

Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Sergei