Hello everyone,
I’d like to propose adding a new shortcut function called delayed_redirect()
to Django.
What is it?
This function returns an intermediate HTML page with a meta refresh tag to redirect users after a short delay. It can be useful for displaying a message (e.g. “You’ll be redirected in 5 seconds”) before redirecting the user.
Why is this useful?
Currently, projects that want this behavior must manually create a template and use render_to_string()
. This function would simplify that and improve UX for redirect flows that involve user confirmation or feedback.
Proposed API:
def delayed_redirect(request, url: str, delay: int = 5) -> HttpResponse:
...
Hi @Mobin-Ghaemi! I think that writing this yourself for your project is probably the best approach here. If you want, you could also build it in a third-party package.
I also think that any automated navigation is not recommended for accessibility reasons. People have reading speeds, particularly when using accesibilty tools, and can also become distracted. If you need a user to read a message before continuing, provide a page with a button.
1 Like
Hi,
Thank you very much for your feedback.
I’ve debugged many projects for others where the frontend handled this timing.
Now, we handle this timing through the backend without any lag.
What’s good about this approach?
It can even be your message for payment, which you often see on most payment pages.
The difference is that from now on, instead of processing on both backend and frontend, it’s handled solely on the backend.
Hello,
I opened a topic on the forum and received two pieces of feedback, but they were not satisfactory.
Since I work at a banking company , I understand the importance of this matter — especially in payment flows where sensitive information is provided and then possibly returned or reused later.
We’ve been using this module unofficially for quite some time in our internal systems. Recently, we decided to make it official so we no longer need to modify the official Django version manually.
Why is this module useful?
After a payment process, users may see certain information on the following pages.
However, due to the complexity of the purchase process in our country, we often use shared systems, or users pay someone else to complete the process on their behalf.
Now imagine someone uses a shared system and views sensitive information.
That confidential data remains visible until the user manually navigates away from the page — either by clicking a button or through a return redirect.
These two methods are rarely used nowadays. Why is that?
Because the transition is handled entirely on the frontend. That means the server doesn’t actually process or control the transition — it’s left to the frontend, which poses security concerns.
Instead of this fragile, two-sided handling with low security, we believe Django can handle it properly and securely using a simple module.
While I agree that a delayed redirect can be useful in certain situations I don’t think it meets the bar for inclusion in Django. Especially since that redirect page generally displays data very specific to that application it is probably better suited and implemented in that application itself (it is one HTML Tag/Header after all)
There is no difference in “server control” and security between using the refresh
header and redirecting with JavaScript. Both are at the discretion of the browser and under user control. The refresh
beahviour can be disabled in browser settings, with extension, or other means. JavaScript can similarly be disabled or patched with extensions.
Perhaps the best next step is making this 3rd-party package? That way you and others can benefit from it more easily than having to build it yourself, and also serves as a test-bed to understand what the API should look like and what features are useful, to then make future integration easier if the demand is truly there.
It’s easier for a feature to be considered if there are numbers to look at for people who want this kind of functionality, rather than just a single passionate champion.