How to use Django to get the name for the host server?

后端 未结 7 2013
天命终不由人
天命终不由人 2020-12-13 17:18

How to use Django to get the name for the host server?

I need the name of the hosting server instead of the client name?

7条回答
  •  醉酒成梦
    2020-12-13 17:33

    Just add to @Tobu's answer. If you have a request object, and you would like to know the protocol (i.e. http / https), you can use request.scheme (as suggested by @RyneEverett's comment).

    Alternatively, you can do (original answer below):

    if request.is_secure():
        protocol = 'https'
    else:
        protocol = 'http'
    

    Because is_secure() returns True if request was made with HTTPS.

提交回复
热议问题