Skip to content Skip to sidebar Skip to footer

How To Know Using Django If Server Is Secure (uses Https)

I work on a Django based app, and I want to know if there's a way to know if my server uses http connections or https. I know that using import socket if socket.gethostname().start

Solution 1:

it's completely possible:

defsome_request_function(request):
    if request.is_secure():
        #You are safe!else:
        #You are NOT safe!

More details: https://docs.djangoproject.com/en/2.0/ref/request-response/#django.http.HttpRequest.is_secure

Solution 2:

django requests (HttpRequest) have is_secure method:

https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.is_secure

Solution 3:

There simply is an is_secure() method on the request object, returning True if the connection is secure.

Depending on your specific server configuration you may also need to set SECURE_PROXY_SSL_HEADER in your settings.

Post a Comment for "How To Know Using Django If Server Is Secure (uses Https)"