django 1.11.x中的urls错误升级到2.0

时间:2018-06-12 13:33:42

标签: python django django-oscar

我正在将我的项目从django 1.11.x迁移到2.0。在我到达网址之前,我一切顺利。我碰巧有这样的导入

from cashondelivery.dashboard.app import application as cod_app

我的网址格式为

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

但我的终端

中出现以下错误
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.

我真的很感激修复。

cashondelivery-> dashboard->应用

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() 

2 个答案:

答案 0 :(得分:4)

您需要放弃include()并直接传递urls

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

urls属性returns a 3-tuple,而不是urlpatterns的列表,并且在Django 2中删除了将其传递给include()的支持。

答案 1 :(得分:1)

django2path代表普通网址,re_path代表网址使用正则表达式。

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