MongoEngine / MongoDB和Django无法在urls.py中“添加更多网址”

时间:2014-06-30 13:14:51

标签: python django

所以我的初始5个网址在urls.py文件中,一切正常。

urlpatterns = patterns('',
url(r'^add/$', PostCreateView.as_view(), name='create'),
url(r'^$', PostListView.as_view(), name='list'),
url(r'^(?P<pk>[\w\d]+)/$', PostDetailView.as_view(), name='detail'),
url(r'^(?P<pk>[\w\d]+)/edit/$', PostUpdateView.as_view(), name='update'),
url(r'^(?P<pk>[\w\d]+)/delete/$', PostDeleteView.as_view(), name='delete'),
)

但是当我添加额外的一行时。我们说

url(r'^test/$', test.as_view(), name='test'),

我遇到500服务器错误页面并通过调试表明存在validation error?

"test is not a valid objectid"

我觉得这是mongoengine的一个问题,但不知道什么或哪里。

1 个答案:

答案 0 :(得分:2)

规则的顺序很重要。此规则将与test/匹配:

url(r'^(?P<pk>[\w\d]+)/$', PostDetailView.as_view(), name='detail'),

定义如下规则:

urlpatterns = patterns('',
url(r'^add/$', PostCreateView.as_view(), name='create'),
url(r'^$', PostListView.as_view(), name='list'),
url(r'^test/$', test.as_view(), name='test'),
url(r'^(?P<pk>[\w\d]+)/$', PostDetailView.as_view(), name='detail'),
url(r'^(?P<pk>[\w\d]+)/edit/$', PostUpdateView.as_view(), name='update'),
url(r'^(?P<pk>[\w\d]+)/delete/$', PostDeleteView.as_view(), name='delete'),
)