Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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().startswith('****'):

I can get the hostname, is it possible to do something like that so I can get to know if the hosting uses a ssl certificate?

PD: I'm a rookie here, so I'm asking to see if it's possible and, if it is, how should I do it. Thanks

like image 779
Sascuash Avatar asked Dec 02 '22 17:12

Sascuash


1 Answers

it's completely possible:

def some_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

like image 156
Pedro Walter Avatar answered Dec 22 '22 10:12

Pedro Walter