添加新网址会出错

时间:2018-01-12 07:49:07

标签: django python-3.x django-urls

在我的urls.py中,我有这个。

from django.conf.urls import include, url
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
from events import views as eviews


urlpatterns = [
    url(r'^user/', include('accounts.urls')),
    url(r'^admin/', include(admin.site.urls)),

    url(r'^$', eviews.events_list, name='events_list'),
    url(r'^(?P<o_type>[-\w]+)/$',
        eviews.events_list,
        name='events_list_by_org'),
    url(r'^(?P<id>\d+)/(?P<slug>[-\w]+)/$',
        eviews.event_detail, name='event_detail'),
]

当我在urlpatterns的第一行添加“user”网址时,它会在第26行显示错误,即“events_list_by_org”网址。当我注释掉或删除“user”网址时,它可以正常工作,但在包含时会显示错误。

1 个答案:

答案 0 :(得分:0)

尝试将您的活动网址分开,例如account个应用中的帐户网址,并将名称地址添加到accountsevents

urls.py in core

urlpatterns = [
    url(r'^user/', include('accounts.urls', namespace='accounts')),
    url(r'^event/', include('event.urls', namespace='event')),
]
事件应用

urls.py

urlpatterns = [
    url(r'^$', eviews.events_list, name='events_list'),
    url(r'^(?P<o_type>[-\w]+)/$',
        eviews.events_list,
        name='events_list_by_org'),
    url(r'^(?P<id>\d+)/(?P<slug>[-\w]+)/$',
        eviews.event_detail, name='event_detail'),
]

也许是因为以下的命名空间,所以尝试将命名空间用于用户网址。