Skip to content
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

Support for url namespaces #3563

Open
oussjarrousse opened this issue Dec 12, 2023 · 4 comments
Open

Support for url namespaces #3563

oussjarrousse opened this issue Dec 12, 2023 · 4 comments

Comments

@oussjarrousse
Copy link

I was trying to include the allauth urls in a namespace as in:

urlpatterns = [
       path('v1/accounts/', include(('allauth.urls', 'allauth'), namespace='v1')),
]

The named urls are now all behind the namespace "v1" and cannot be reversed using the url name alone as in reverse(url_name). Currently the django.url.reverse() function is used throughout the project with named urls without any consideration for url namespaces.

The solution is to use something like:

url_name = "the_actual_name_as_it_was_previously_defined"
namespace = request.reverse_match.namespace
if namespace:
   url_name = f"{namespace}:{url_name}"
url = reverse(url_name)

What do you think about this issue, and do you think it is a good idea to work on it?

https://docs.djangoproject.com/en/5.0/topics/http/urls/#url-namespaces

@oussjarrousse oussjarrousse changed the title Support for url names Support for url namespaces Dec 12, 2023
@pennersr
Copy link
Owner

allauth was conceived at around the same time Django namespaces were introduced, so historically it started out without namespaces. Currently, all url names still use prefixes, such as "account_login", and "mfa_activate_totp". and you can argue that those should already be properly using namespaces: "account:login" and "mfa:activate_totp". Though, trying to adjust to this retroactively is a big backwards compatibility issue, which is why so far that never materialized, and even newer views consistently used the prefixed approach.

If your proposal is to take a first stab at making reversal namespace aware without breaking backwards compatiblity, then definitely, that is in any case a good thing to have. If you are referring to breaking backwards compatibility, then I would like to see more opinions on the matter first, and perhaps an investigation in how to ease the transition (e.g. ACCOUNT_URLNAME_PREFIX = "account:" | "account_" ?).

@varunsaral
Copy link
Contributor

varunsaral commented Jan 2, 2024

@pennersr can i attempt this?

@pennersr
Copy link
Owner

pennersr commented Jan 7, 2024

@pennersr can i attempt this?

As mentioned above, this is a big backwards compatibility issue, would like to get some opinions from other users on the matter first, as well as a decent proposal on how to move forward.

@varunsaral
Copy link
Contributor

Understood @pennersr . On the side note, i was wondering if it's possible to write you one email. I tired looking it up but couldn't find any.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants