我更新帖子后,我想重定向回我的详细信息页面。但它不起作用。继承人我的网址
url(r'^(?P<id>\d+)/$', post_detail, name='detail'),
这是我的观点
def post_update(request, id=None):
instance = get_object_or_404(Post, id=id)
form = PostForm(request.POST or None, instance=instance)
if form.is_valid():
instance = form.save(commit=False)
instance.save()
return HttpResponseRedirect(reverse('posts:list', args=id))
context = {
"title": instance.title,
"instance": instance,
"form": form
}
return render(request, "posts/post_form.html", context)
这是我收到的错误消息
Reverse for 'list' with arguments '('3',)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['posts/$']
我也试过改变这个
return HttpResponseRedirect(reverse('posts:list', args=id))
到这个
return HttpResponseRedirect(reverse('posts:list', args=instance.id))
和
return HttpResponseRedirect(reverse('posts:list', args=Post.id))
如何更正
答案 0 :(得分:1)
您是重定向到list
网址,但是想要重定向到detail
?
return HttpResponseRedirect(reverse('posts:detail', args=id))