django 1.11.x 中的 url 错误升级到 2.0
urls error in django 1.11.x upgrade to 2.0
我正在将我的项目从 django 1.11.x 迁移到 2.0。在 url 之前,我一切顺利。我碰巧有这样的导入
from cashondelivery.dashboard.app import application as cod_app
我的 url 模式为
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.
非常感谢修复。
现金配送->仪表板->应用程序
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()
在 django2
中,它的 path
用于正常 url 和 re_path
用于 url 使用正则表达式。
path('dashboard/cod/', include(cod_app.urls)),
您需要删除 include()
并直接传递 urls
:
url(r'^dashboard/cod/', cod_app.urls),
urls
属性 returns a 3-tuple,不是 urlpatterns
的列表,并且在 Django 2 中删除了将其传递给 include()
的支持。
我正在将我的项目从 django 1.11.x 迁移到 2.0。在 url 之前,我一切顺利。我碰巧有这样的导入
from cashondelivery.dashboard.app import application as cod_app
我的 url 模式为
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.
非常感谢修复。
现金配送->仪表板->应用程序
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()
在 django2
中,它的 path
用于正常 url 和 re_path
用于 url 使用正则表达式。
path('dashboard/cod/', include(cod_app.urls)),
您需要删除 include()
并直接传递 urls
:
url(r'^dashboard/cod/', cod_app.urls),
urls
属性 returns a 3-tuple,不是 urlpatterns
的列表,并且在 Django 2 中删除了将其传递给 include()
的支持。