So as we know when we use the dash pages
in each page we have a layout function (it can be a variable but in my case I need a function)
now I get an argument of id in the layout function and I need to check if the id is a number if not I want to redirect the user to an external 404 page
if not plan_id.isnumeric():
abort(404)
any idea how I can do this?
(tried using the flask abort and redirect functions doesn’t work)
It’s on another network so that would be a challenge let’s see if we can figure this out without an MRE.
I have a page where in the URL you are supposed to get an id
localhost:8080/great-app/5
5 is the id
def layout(plan_id):
if not plan_id.isnumeric():
abort(404) # Try 1 The redirect and abort is two different things I tried
redirect('external url') # Try 2 # And didn't work
now the function where I check before_request For some reason dash calls the before_request every second so except from my sso check that I have no other way to do it I try to avoid the decorator
Also @jinnyzor If I go to another page through dcc link when I printed the URLs in the before_request it didn’t print the new URL just the update-component, reload-hash, graph.js and so on no where can I get the URL with the argument in the before_request
@jinnyzor I made a bit of progress but I am still stuck.
I found out how to get the last part of the URL check if it’s a number and try to redirect the page but I get a Redirect is not allowed for a preflight request.
@server.before_request
def requestCheck():
if request.method == 'GET' and request.referrer is not None:
referrer = request.referrer.split('/')
if referrer[-3] == 'page1' and referrer[-2] == 'main':
if referrer[-1] and not referrer[-1].isnumeric():
return redirect(external link)
let’s say I have the link
localhost:8080/page1/main/5f
the last part 5f is not a number so its suppose to redirect to the external link but I get the error above
I am using dash pages, I don’t want to switch to using dcc location instead, and start switching between pages using the URL instead of automatically with dash pages…