ImproperlyConfiguredError about app_name when using namespace in include()

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')),

Django 1.11+, 2.0+

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

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

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 https://docs.djangoproject.com/en/1.11/ref/urls/#include :

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.

( https://docs.djangoproject.com/en/1.11/topics/http/urls/#namespaces-and-include )


Django 2.0 you should specify app_name in your urls.py, 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')),
    path('admin/', admin.site.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: https://code.djangoproject.com/ticket/28691 Django 2.0 Docs