Closed Mte90 closed 3 months ago
It looks as if you were trying to redirect to the same URL on which you are. In this case nothing will happen, unless you add HX-Refresh
header to the response. See the htmx.js code:
var shouldRefresh = hasHeader(xhr, /HX-Refresh:/i) && "true" === xhr.getResponseHeader("HX-Refresh");
if (hasHeader(xhr, /HX-Redirect:/i)) {
location.href = xhr.getResponseHeader("HX-Redirect");
shouldRefresh && location.reload();
return;
}
It does not seem you can do this by using django-htmx
directly, because HttpResponseClientRedirect
and HttpResponseClientRefresh
do not seem to be able to be used at the same time.
No I am trying to redirect to the homepage in case the login (that is another page) success.
The home page already has the decorator for login_required
I would suggest using a browser network panel to see what headers the redirect brings and putting breakpoint to proper place in htmx.js to see whether location.href changes and/or reload is made.
Another solution it is more simple as it is the login, when is successful that page automatically should redirect to the home page, so if I do a refresh of the login page when it is successful it should be enough to get the same behavior.
Sorry, I cannot provide support on this issue tracker.
Python Version
3.11
Django Version
4.x
Package Version
1.17.x
Description
So I have this code but the redirect is not working, there is just a replacement in the div on success. I can see that the cookie is not configured for the login with that, but on the django admin it works.
My form:
My function: