How to get the output of a for loop using the variable of another for loop in Python-Flask

I don't know if that is the right term for my problem, I hope you can understand it. The purpose of this is to collect files from ftp with a combination of account name and date of the filename I have this program in Python using Flask Framework with a Database account_names

The template have two dates - from date and to date and I will get the between dates of it. I created for loop to get the region in my Database and another for loop to get to get the dates between the two dates. In this for loop, I created variable idDate combines the names from database and the output of the dates and a for loop for files from ftp.

For this, I want to collect the files using the output in idDate to the for loop of file. This works on my another program that only gets a single date. But when I did it with a multiple dates, there's no output from my print

c, conn = connection()

data_name = c.execute("SELECT acct_value FROM account_names ORDER BY region ASC")
data_name = c.fetchall()

current_path = os.getcwd()
save_path = str(current_path) + '/logs/'
ftp_directory = '/R03/sqa/logs/'
chk_log_dir = os.path.isdir('logs')

strdate = datetime.datetime.strptime(from_collect_tab, "%Y-%m-%d")
endate = datetime.datetime.strptime(to_collect_tab, "%Y-%m-%d")

frm_month = strdate.month
frm_day =
frm_year = strdate.year

to_month = endate.month
to_day =
to_year = endate.year

for names in data_name:
    region = c.execute("SELECT region FROM account_names WHERE acct_value = (%s)", (names[0]))
    region = c.fetchone()

    def daterange(date1, date2):
        for n in range(int ((date2 - date1).days)+1):
            yield date1 + timedelta(n)

    start_dt = date(frm_year, frm_month, frm_day)
    end_dt = date(to_year, to_month, to_day)

    for dt in daterange(start_dt, end_dt):
        out_dates = dt.strftime("%Y-%m-%d")

        idDate = names[0] + "-" + out_dates

        # print(idDate)
        if chk_log_dir == True:
            ftp = ftpconnection()
            ftp.cwd(ftp_directory + region[0])
            files = ftp.nlst()

            for file in files:
                # print(file)
                if idDate in file:
                    # ftp.retrbinary('RETR ' + file , open(save_path + file, 'wb').write)
                    # print(file)