我在开发一个基于 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/