robinhood / deux

Multifactor Authentication for Django Rest Framework
Other
155 stars 56 forks source link

Django 2 error: Specifying a namespace in include() without providing an app_name #20

Open lopezjurip opened 6 years ago

lopezjurip commented 6 years ago

When using this library with Django 2 like:

from django.urls import include, path

urlpatterns = [
    # ...
    path('mfa/', include("deux.urls", namespace="mfa")),
]

Fails with:

Specifying a namespace in include() without providing an app_name '
django.core.exceptions.ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported. Set the app_name attribute in the included module, or pass a 2-tuple containing the list of patterns and app_name instead.

To make this work we need to add the variable app_name to

deux/urls.py deux/oauth2/urls.py deux/authtoken/urls.py

gonzaloamadio commented 5 years ago

with which value?

VirtualKley commented 5 years ago

Use app_name='nameapp' in urls for applications, after urlpatterns

rozacek commented 4 years ago

Can you provide a code example? Because as I'm typing app_name="sth" in urls.py it doesn't work.

GabrielDumbrava commented 4 years ago

Can you provide a code example? Because as I'm typing app_name="sth" in urls.py it doesn't work.

Let's say in your main urls.py you want to include the urls of an app, called shop_app, like this: path("shop/", include("shop_app.urls", namespace='shop')),

Then, in your urls.py file of your shop_app located in shop_app/urls.py, after the urlpatters add the app_name like this:

urlpatterns = [
   ... some patterns
]

app_name = 'shop'

If you don't have access to the shop_app urls, as in case you are using an included package, then you'll have to drop the namespace from your main include and remove the namespace references from your url tags, or from your reverse functions.

DonExo commented 4 years ago

Or you can also use it this way:

path('mfa/', include(("deux.urls", 'app_name'), namespace="mfa")),

amontecino commented 4 years ago

Excelent ¡¡¡

Gathiira commented 2 years ago

as indicated by @DonExo

path('', include(('blog.urls', 'blog'), namespace='blog'))