我有一个名为工作区的应用程序,
在我的 form_valid 定义中的某处
def form_valid(self, form):
obj = form.instance
obj.owner = self.request.user
obj.sort_order = Project.default_sort_order()
obj.workspace = get_object_or_404(Workspace, pk=self.kwargs['pk'])
context = self.get_context_data()
attribute_form = context['attribute_formset']
if attribute_form.is_valid():
self.object = form.save()
for aform in attribute_form:
aform.instance.owner = self.request.user
attribute = aform.save()
self.object.attributes.add(attribute)
return HttpResponseRedirect(reverse(self.get_success_url()))
else:
return self.render_to_response(self.get_context_data(form=form))
以及我对 get_success_url 的定义:
def get_success_url(self):
return reverse('workspace_project', kwargs={'pk':self.object.pk})
我的网址定义是:
url(r'^project/(?P<pk>\d+)$', ProjectDetailView.as_view(), name='workspace_project'),
它包含在主 urlconf 中,如下所示:
url('^workspace/', include('workspace.urls')),
但是,每当创建成功时,我都会收到此重定向错误:
NoReverseMatch at /workspace/workspace/3/create_project
Reverse for '/workspace/project/12' with arguments '()' and keyword arguments '{}' not found.
我访问了网址/workspace/project/12
,我可以访问它。为什么这会出错呢?
提前致谢!