gpt4 book ai didi

python - Django urls 调度程序错误 (urls.E004) 确保 urlpatterns 是 url() 实例的列表

转载 作者:太空宇宙 更新时间:2023-11-03 14:58:00 25 4
gpt4 key购买 nike

我正在尝试将国际化添加到我的 Django 项目中。然后我将 i18n_patterns() 添加到我的主要 urls.py 我有以下问题:

ERRORS:
?: (urls.E004) Your URL pattern [<RegexURLResolver <module 'coffeebar.urls' from './coffee/coffeebar/urls.py'> (coffeebar:coffeebar) ^bar/>, <RegexURLResolver <RegexURLPattern list> (admin:admin) ^admin/>] is invalid. Ensure that urlpatterns is a list of url() instances.

./coffee/coffee/urls.py(主要 url 配置)

from django.conf.urls import include, url
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin


urlpatterns = i18n_patterns([
url(r'^bar/', include('coffeebar.urls')),
url(r'^admin/', admin.site.urls),
])

./coffee/coffeebar/urls.py(包含 url 配置)

from django.conf.urls import url, include
from django.contrib.auth import views as auth_views

from . import views

app_name = 'coffeebar'

order = [
url(r'^$', views.order_details, name='index'),
url(r'^(?P<order_id>[0-9]+)/$', views.order_details, name='details'),

url(r'^add/$', views.order_add_item, name='add'),
url(r'^remove/$', views.order_remove_item, name='remove'),
url(r'^checkout/$', views.order_checkout, name='checkout'),
url(r'^list/$', views.order_list, name='list'),
]

admin = [
url(r'^$', views.admin, name='index'),
url(r'^accounts/', include([
url(r'^$', views.admin_accounts, name='index'),
url(r'^open/$', views.admin_accounts, {'action': 'open'}, name='open'),
url(r'^close/$', views.admin_accounts, {'action': 'close'}, name='close'),
], namespace='accounts')),

url(r'^orders/', include([
url(r'^$', views.admin_orders, name='index'),
url(r'^update/', views.admin_orders, {'action': 'update'}, name='update'),
], namespace='orders')),

url(r'^products/', include([
url(r'^$', views.admin_products, name='index'),
url(r'^add/$', views.admin_products, {'action': 'add'}, name='add'),
url(r'^(?P<product_id>[0-9]+)/', views.admin_products, {'action': 'edit'}, name='edit'),
url(r'^(?P<product_id>[0-9]+)/toggle/$', views.admin_products, {'action': 'toggle'}, name='toggle'),
url(r'^(?P<product_id>[0-9]+)/delete/$', views.admin_products, {'action': 'delete'}, name='delete'),
], namespace='products')),
]

urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'order/', include(order, namespace='order')),
url(r'admin/', include(admin, namespace='admin')),

# django auth
url(r'^login/$', auth_views.login, {'template_name': 'login.html'}, name='login'),
url(r'^logout/$', auth_views.logout, {'template_name': 'logout.html'}, name='logout'),
]

最佳答案

删除括号,更改:

urlpatterns = i18n_patterns([
url(r'^bar/', include('coffeebar.urls')),
url(r'^admin/', admin.site.urls),
])

到:

urlpatterns = i18n_patterns(
url(r'^bar/', include('coffeebar.urls')),
url(r'^admin/', admin.site.urls),
)

关于python - Django urls 调度程序错误 (urls.E004) 确保 urlpatterns 是 url() 实例的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41050304/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com