阅读量: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/