如果服务器安全,如何知道使用Django(使用https) [英] How to know using Django if server is secure (uses https)

查看:134
本文介绍了如果服务器安全,如何知道使用Django(使用https)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在基于Django的应用程序上工作,我想知道是否有办法知道我的服务器是使用http连接还是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.

我知道使用

import socket
if socket.gethostname().startswith('****'):

我可以获得主机名,是否可以做类似的事情以便我可以了解主机是否使用ssl证书?

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:我是新手,所以我要问看是否可能,如果是,我该怎么办
谢谢

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

推荐答案

完全有可能:

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

更多详情:
https://docs.djangoproject.com/en/2.0/ref/request-response/#django。 http.HttpRequest.is_secure

这篇关于如果服务器安全,如何知道使用Django(使用https)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆