King
King

Reputation: 2025

urls error in django 1.11.x upgrade to 2.0

I am migrating my project from django 1.11.x to 2.0. I have everything going well till I got to urls. I happen to have an import like this

from cashondelivery.dashboard.app import application as cod_app

and I have my url pattern as

url(r'^dashboard/cod/', include(cod_app.urls)),

but I got the following error in my terminal

url(r'^dashboard/cod/', include(cod_app.urls)),
  File ".../dev/lib/python3.6/site-packages/django/urls/conf.py", line 27, in include
    'provide the namespace argument to include() instead.' % len(arg)
django.core.exceptions.ImproperlyConfigured: Passing a 3-tuple to include() is not supported. Pass a 2-tuple containing the list of patterns and app_name, and provide the namespace argument to include() instead.

I would really appreciate a fix.

cashondelivery->dashboard->app

import django
from django.conf.urls import url
from django.contrib.admin.views.decorators import staff_member_required

from oscar.core.application import Application

from . import views


class CashOnDeliveryDashboardApplication(Application):
    name = None
    default_permissions = ['is_staff', ]

    list_view = views.TransactionListView
    detail_view = views.TransactionDetailView

    def get_urls(self):
        urlpatterns = [
            url(r'^transactions/$', self.list_view.as_view(),
                name='cashondelivery-transaction-list'),
            url(r'^transactions/(?P<pk>\d+)/$', self.detail_view.as_view(),
                name='cashondelivery-transaction-detail'),
        ]

        if django.VERSION[:2] < (1, 8):
            from django.conf.urls import patterns

            urlpatterns = patterns('', *urlpatterns)

        return self.post_process_urls(urlpatterns)


application = CashOnDeliveryDashboardApplication() 

Upvotes: 2

Views: 860

Answers (2)

solarissmoke
solarissmoke

Reputation: 31424

You need to drop the include() and just pass the urls directly:

url(r'^dashboard/cod/', cod_app.urls),

The urls property returns a 3-tuple, not a list of urlpatterns, and support for passing this to include() was dropped in Django 2.

Upvotes: 4

Astik Anand
Astik Anand

Reputation: 13047

In django2 its path for normal url and re_path for url using regex.

path('dashboard/cod/', include(cod_app.urls)),

Upvotes: 1

Related Questions