I use django 2.0.7
in my project with django-decorator-include
app (version 2.0).
My urls.py:
from django.conf import settings
from django.contrib import admin
from django.urls import path, re_path, include
from django.conf.urls.static import static
from django.conf.urls.i18n import i18n_patterns
from django.contrib.auth.decorators import login_required
from decorator_include import decorator_include
urlpatterns = i18n_patterns(
path('', include('web.urls', namespace='web')),
path('backoffice/', decorator_include([login_required,], 'backoffice.urls', namespace='backoffice')),
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
My backoffice.urls
:
from django.urls import path, re_path
from django.conf.urls.i18n import i18n_patterns
from django.utils.translation import gettext_lazy as _
from backoffice import views
app_name = 'backoffice'
urlpatterns = (
path('', views.DashboardView.as_view(), name='dashboard'),
)
backoffice
is added to INSTALLED_APPS.
In my views (in app web
for example) I am able to do reverse URL, for example in my login view I do return redirect('backoffice:dashboard')
and it works just perfectly - its redirecting to /backoffice/.
Problem is when I try to do reverse urls in my templates. In one of my templates, when I add code:
<li class="featured"><a href="{% url 'backoffice:dashboard' %}">{% trans 'Open dashboard' %}</a></li>
I get django error:
NoReverseMatch at /
'backoffice' is not a registered namespace
I suppose that problem is related to django-decorator-include, because if I change my include to standard django url include:
path('backoffice/', include('backoffice.urls', namespace='backoffice')),
it works just fine, and I am able to get reverse urls in templates again. What should I do? Maybe its a bug in django-decorator-include? Any ideas how can I solve that?