def dump_environment(config, prefix="DJANGO_ENV_", export=True):
    """Dump configuration as an environment variable string.

    Parameters
    ----------
    config : dict
        The configuration dict.
    prefix : string, default="DJANGO_ENV_"
        Prefix for environment variables.  This prefix should be
        prepended to all valid variable names in the environment.
    export : boolean, default=True
        Prepend each environment variable string with "export ", or
        not.

    Returns
    -------
    string
        The current configuration as a string setting environment
        variables.
    """
    stack = []
    dumps = []
    if export:
        exp = "export "
    else:
        exp = ""

    # Convert the config dict into a list (stack).
    for (k, v) in config.items():
        stack.append((k, v))

    while stack:
        (k, v) = stack.pop(0)
        if isinstance(v, list):
            for (i, sv) in enumerate(v):
                stack.append((f"{k}_{i}", sv))
        elif isinstance(v, dict):
            for (sk, sv) in v.items():
                stack.append((f"{k}_{sk}", sv))
        else:
            dumps.append(f"{str(k)}='{str(v)}'")

    return "\n".join(f"{exp}{prefix}{line}" for line in dumps)