所以我的初始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的一个问题,但不知道什么或哪里。
答案 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'),
)