-
-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add relative current_url #259
Comments
I wouldn't feel comfortable just dropping the origin, as it's potentially security-relevant information. Some projects are deployed with multiple origins. Instead, why not compare with absolute URL's? I don't quite know what you're trying to do, but perhaps you could use something like this: if request.htmx.current_url == request.build_absolute_uri('/login/'): |
@adamchainz I wasn't trying to compare, but was instead redirecting to a login page while specifying a Instead of this: path = urlunparse(
urlparse(self.request.htmx.current_url)._replace(netloc="", scheme="")
)
response = redirect_to_login(
path,
resolve_url(self.get_login_url()),
self.get_redirect_field_name(),
)
return HttpResponseClientRedirect(response.url) I wanted to be able to do this: response = redirect_to_login(
self.request.htmx.relative_current_url,
resolve_url(self.get_login_url()),
self.get_redirect_field_name(),
)
return HttpResponseClientRedirect(response.url) In my case I plan to force redirects often with |
Yeah I think adding the helper is probably too niche/security sensitive to solve here. Calling Django’s
How exactly? (P.S. you probably want to use |
I do agree that the specific use case I showed is a hack that isn't wise. That was the first case that came up and I haven't yet refactored that code. I just came across another case today though. Something like this in a non-HTMX Django page: {% url "users:login" %}?next={{ request.get_full_path }} Doesn't have an equivalent in django-htmx land without a custom template filter/tag. {% url "users:login" %}?next={{ request.htmx.relative_current_url }}
From my testing, passing an absolute URL to
Ah I do. Thanks for noting that! |
Added in #287, as I did and a bit of research to check naming, and was reminded that relative URL’s mean “relative to a given base URL |
Description
current_url
returns the full URL:I'd like a way to access just the non-domain part of this URL (I'm using it for a
?next=
login redirect).I imagine something like this might work.
The text was updated successfully, but these errors were encountered: