ImproperlyConfiguredError about app_name when using namespace in include()

Posted on

Question :

ImproperlyConfiguredError about app_name when using namespace in include()

I am currently trying out Django. I use the namespace argument in one of my include()s in When I run the server and try to browse,
I get this error.

File "", line 39, in include
    '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.

These are my files:


from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    url(r'^reviews/', include('reviews.urls', namespace='reviews')),
    url(r'^admin/', include(,



from django.conf.urls import url

from . import views

urlpatterns = [
    # ex: /
    url(r'^$', views.review_list, name='review_list'),
    # ex: /review/5/
    url(r'^review/(?P<review_id>[0-9]+)/$', views.review_detail, name='review_detail'),
    # ex: /wine/
    url(r'^wine$', views.wine_list, name='wine_list'),
    # ex: /wine/5/
    url(r'^wine/(?P<wine_id>[0-9]+)/$', views.wine_detail, name='wine_detail'),

What do I pass the app_name as stated in the error message?

Asked By: Nelson M


Answer #1:

Check the docs for include here.

What you’ve done is not an acceptable way of passing parameters to include. You could do:

url(r'^reviews/', include(('reviews.urls', 'reviews'), namespace='reviews')),
Answered By: unixia

Answer #2:

Django 1.11+, 2.0+

You should set the app_name in the urls file you are including

# reviews/  <-- i.e. in your app's

app_name = 'reviews'

Then you can include it the way you are doing it.

Also, it might be worth noting what Django docs say here :

Deprecated since version 1.9: Support for the app_name argument is
deprecated and will be removed in Django 2.0. Specify the app_name as
explained in URL namespaces and included URLconfs instead.

( )

Answered By: Bob

Answer #3:

Django 2.0 you should specify app_name in your, is not necessary to specify app_name argument on include.

Main Url file.

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('', include('apps.main.urls')),

Included Url.

from django.urls import path
from . import views

app_name = 'main_app'

urlpatterns = [
    path('', views.index, name='index'),

Then use use in template as

<a href="{% url main_app:index' %}"> link </a>

More details:
Django 2.0 Docs

Answered By: Brayan Loayza

Answer #4:

I included a library not (fully) django 2.1 compatible yet (django_auth_pro_saml2). Hence I create a second file

from django_saml2_pro_auth.urls import urlpatterns

app_name = 'saml'

Such that I could include the urls as:

from django.urls import include, re_path as url

urlpatterns = [
    ..., url(r'', include('your_app.saml_urls', namespace='saml')), ...

Hacky, but it worked for me, whereas the url(r'^reviews/', include(('reviews.urls', 'reviews'), namespace='reviews')) did not.

Answered By: Herbert

Answer #5:

I am also face the same error in Django 2.2 and i solve it this way file

urlpatterns = [
   path('publisher-polls/', include('polls.urls', namespace='publisher-polls')),

polls/ file

app_name = 'polls'
urlpatterns = [
  path('', views.IndexView.as_view(), name='index')

example use of namespace in calss based view method

def get_absolute_url(self):
    from django.urls import reverse
    return reverse('polls.index', args=[str(])

example use of namespace in templates

{% url 'polls:index' %}

Here polls:index mean app_name[define in polls/ file]:name[define in polls/ file inside path function]

their official which is pretty good you can check for more info namespace_django_official_doc

Answered By: sayalok

Leave a Reply

Your email address will not be published.