(request)
return ip
获取客户端ip
获取客户端ip
获取客户端ip
def get_ip(request):
    """获取客户端ip"""
    if not request:
        return None
    x_forwarded_for = request.META.get("HTTP_X_FORWARDED_FOR")
    if x_forwarded_for:
        ip = x_forwarded_for.split(",")[0]
    else:
        ip = request.META.get("REMOTE_ADDR")
    return ip
def get_ip ( request ) : if not request : return None x_forwarded_for = request . META . get ( "HTTP_X_FORWARDED_FOR" ) if x_forwarded_for : ip = x_forwarded_for . split ( "," ) [ 0 ] else : ip = request . META . get ( "REMOTE_ADDR" ) return ip