python - 如果服务器安全(使用 https),如何知道使用 Django

标签 python django ssl https ssl-certificate

我在开发一个基于 Django 的应用程序,我想知道是否有办法知道我的服务器是使用 http 连接还是 https。

我知道用

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

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

PD: 我是这里的菜鸟,所以我想看看是否可行,如果可行,我应该怎么做。 谢谢

最佳答案

完全有可能:

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

关于python - 如果服务器安全(使用 https),如何知道使用 Django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21632587/

相关文章:

javascript - 关于 django/javascript 模式以及如何最好地组织/封装的一般查询

python - Django-rest框架结构不捕获post或put请求

ssl - 使用 curl -with --cert

http - 当通过 https 发出原始请求时,在 Location-header 中获取 http

python - BeautifulSoup 汉字编码错误

python - 如何找到字符串的一部分?

mysql - (1406, "Data too long for column ' sr_number' at row 1") 在 Django 中收到帖子并保存到数据库后

android - javax.net.ssl.SSLException : Write error: ssl=0x7f70604080: I/O error during system call, 管道损坏

python - 有条件地分配 DataFrame 中另一列的值

python - 返回 3D scipy.spatial.Delaunay 的表面三角形