后端获取服务器的IP地址和端口等路径

avatar
作者
猴君
阅读量:1

【Django】request获取IP地址及端口 

1. get_host() 获取ip地址
IP6 = request.get_host()  # IP6: 192.168.123.168:8002
2. get_port() 获取端口号
ip7 = request.get_port()  # ip7: 8002
3. build_absolute_uri() 获取 完整ip及端口
IP1 = request.build_absolute_uri("/")  # 获取 当前ip及端口 IP1: http://192.168.123.167:8002/ ip2 = request.build_absolute_uri()  # 获取 当前访问的url, ip2: http://192.168.123.167:8002/api/service/monitpointdata/export_data/ ip3 = request.build_absolute_uri("media")  # 获取 当前访问的url 连接 media ,ip3: http://192.168.123.167:8002/api/service/monitpointdata/export_data/media ip4 = request.build_absolute_uri("/media/")  # ip4: http://192.168.123.167:8002/media/ ip5 = request.build_absolute_uri(settings.MEDIA_URL)  # http://192.168.123.167:8002/data/ 

 

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!