views.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:bbs 作者: eenot 项目源码 文件源码
def edit(request,topic_id):

    try:
        topic = Topic.objects.get(id=topic_id)
        if topic.author != request.user:
            raise Http404
    except Node.DoesNotExist:
        raise Http404

    if request.method == 'POST':
        form = TopicForm(request.POST)
        if form.is_valid():
            topic.title = form.clean()['title']
            topic.content = form.clean()['content']
            topic.updated_on = timezone.now()
            topic.save()
            return HttpResponseRedirect(reverse("bbs:topic" ,args=(topic.id,)))
    else:
        form = TopicForm(instance=topic)

    return render(request,'bbs/edit.html',{'topic':topic,'form':form})
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号