Dash app.routes Flask to Dash

Hello,
I have a main application written in Dash, at the moment I’m trying to implement routing where I could take a token and then perform the necessary operations with it,
Could you tell me how you can transfer a token to Dash applications?
Thank you

for examples:

# API routing
@app.server.route('/api/<token>', methods=['GET','POST'])
def generate_report(token):
    db = Token()
    check_access = db.get_list_tocken(token)
    if check_access == 'denied':
        return 'access denied'
1 Like

Here is an example from my app:

@app.server.route(/api/callback/')
def callback():
    code = request.args.get('code')

So code would be the value 1234 with the following URL:

http://localhost:8000/api/callback/?code=1234

Hello,
Thank you, Could you tell me how can I pick up ‘code ’ from @app.server.route(/api/callback/’) routing and transfer to @app.callback
?

You’d probably need to store the ‘code’ value on the back-end (e.g., database, file) and then retrieve it in the callback. Personally, I use flask-session, flask-redis, and Redis to store/retrieve session data for each user.

do you have an example with saving code to cache?
appropriately pick up the value given in the request
Thank you

so I did it as follows, I don’t know how much correct it will be:


#API routing
@app.server.route('/api/<token>', methods=['GET','POST'])
def generate_report(token):
    db = Token()
    check_access = db.get_list_tocken(token)
    if check_access == 'denied':
        return 'access denied'
    else check_access == 'ok':
        app.layout = access_page
        return app.index()

@app.callback(....... Input('url', 'pathname'))
def generate_report(........, pathname):
    token = pathname.split('/')[2]

Dear cufflink, this method is fine but what is request ? How is request defined ?

@app.server.route(/api/callback/')
def callback():
code = request.args.get(‘code’)

Jhave just found that request is:

flask.request.args.get(‘code’)

it works. Thanks a lot