How to get POST parameters in a Django view protected by @login_required?

240 Views Asked by At

Django's login_required decorator requires a login before proceeding to any functionality in a view function. If a user is not logged in, they will be redirected through a login screen.

If the HTTP request is a GET, Django sometimes puts the GET destination in a parameter ("next"). Or, Django also has a LOGIN_REDIRECT_URL setting that is a URL a user is forwarded to after login.

If the HTTP request is a POST, that POST data is lost during the login process.

What is the best way to preserve the original URL and POST data for the original POST request, and re-post that data after the user is logged in?

I imagine putting something in a session, but I'd have to intercept the POST data and URL on the way through login_required. The best practice is not obvious to me.

0

There are 0 best solutions below