✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🧬 Learn how to build RNA-Seq data apps with Python & Dash. Register for the May 20 Webinar!

Session id on dash application

I’m developing a small Dash application based on sessions into a Flask environment that generates a file to print, including the session_id in the name (for user concurrence). When the user close session, the file is deleted.
The problem is that if I refresh the page, the session_id changes and then the file is not deleted successfully.
This is the code:



app = dash.Dash(__name__,server=server,routes_pathname_prefix='/dash/', external_stylesheets=external_stylesheets)

@server.route('/', methods=['GET', 'POST'])
def index():
    if request.method=='POST':
        return redirect('/dash')
    return  '''
       <form method="post">
            <p><input type=text name=username>
            <p><input type=submit value=Login>
def clearfiles(session_id):
    if os.path.exists("C:/xampp/htdocs/file"+session_id+".docx"):
    return redirect(url_for('index'))

def serve_layout():
    return html.Div([
    html.Button(id="generate-file", n_clicks=0, children="generate-file"),
    html.A(html.Button('Close session'), href="../logout/"+session_id)
    html.Div(session_id, id="session-id",
                    style={'display': 'none'})

I could generate the session_id in the index page and pass it to dash page. The problem is, as dash is not described into a server.route clause, it’s not that immediate for me. I’m stuck.
Any idea? I would really appreciate!