How do I redirect to a page only from a specific page and not directly in Django?

Hi there,

I have a lot of pages (urls) in my app. But there’s one page (url) let’s say Page/URL A which I want for user to land/visit only if he/she comes/redirects from another specific url let’s say Page/URL B. I don’t want user to view Page/URL A directly if the user put url in the browser.

To ease the help, I am posting the urls of both pages.

Page/URL A is:

path("invite-user/", InviteUser.as_view(), name="invite_user"),  # Invite User Page

and Page/URL B is:

path(
        "switch-workspace/", SwitchWorkspace.as_view(), name="switch_workspace"
    ),  # Switch Workspace Page

Can someone help me to accomplish it?

The only way I can think of that can come close (but still not enforce or guarantee) would be to generate a 1-time use token in PageA that is passed through the browser (cookie, url parameter, etc) to PageB, and is validated by PageB. Still doesn’t guarantee that you came directly from PageA, but is probably adequate for all practical purposes.

1 Like