本文整理汇总了Python中blog.forms.CommentForm.save方法的典型用法代码示例。如果您正苦于以下问题:Python CommentForm.save方法的具体用法?Python CommentForm.save怎么用?Python CommentForm.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.forms.CommentForm
的用法示例。
在下文中一共展示了CommentForm.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_comment
# 需要导入模块: from blog.forms import CommentForm [as 别名]
# 或者: from blog.forms.CommentForm import save [as 别名]
def edit_comment(request, comid):
context=RequestContext(request)
com=Comment.objects.get(pk=comid)
form= CommentForm(request.POST or None, instance=com)
if form.is_valid():
form.save()
return added(request)
return render_to_response('blog/edit_comment.html', {'form':form, 'comid':comid}, context)
示例2: post
# 需要导入模块: from blog.forms import CommentForm [as 别名]
# 或者: from blog.forms.CommentForm import save [as 别名]
def post(self, request, pk):
# return HttpResponse(request.POST['entry_id'])
form = CommentForm(request.POST, request.FILES)
if form.is_valid():
form.save()
return HttpResponse("Your comment submitted successfully")
else:
self.kwargs["forms"] = form
return self.render_to_response(self.get_context_data(forms=form))
示例3: forms
# 需要导入模块: from blog.forms import CommentForm [as 别名]
# 或者: from blog.forms.CommentForm import save [as 别名]
def forms(request, article_id):
if request.POST:
new_form = CommentForm(request.POST)
if new_form.is_valid():
print(request.POST, new_form.errors, new_form.cleaned_data)
comment = new_form.save(commit=False)
comment.comment_article = Article.objects.get(id=article_id)
new_form.save()
return redirect('/article/get/%s/' % article_id)
示例4: post
# 需要导入模块: from blog.forms import CommentForm [as 别名]
# 或者: from blog.forms.CommentForm import save [as 别名]
def post(self, request, *args, **kwargs):
self.object = self.get_object()
form = CommentForm(object=self.object, data=request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect(self.object.get_absolute_url())
context = self.get_context_data(object=self.object, form=form)
return self.render_to_response(context)
示例5: addcomment
# 需要导入模块: from blog.forms import CommentForm [as 别名]
# 或者: from blog.forms.CommentForm import save [as 别名]
def addcomment(request, article_id):
if request.POST and ('pause' not in request.session):
form = CommentForm(request.POST)
if form.is_valid:
comment = form.save(commit=False) # запрещаем автосохранение комментария
comment.comment_article = Articles.objects.get(id=article_id)
form.save()
request.session.set_expiry(60)
request.session['pause'] = True
return redirect('/articles/get/%s/' % article_id) # редирект на ту же статью на которой оставлен коммент
示例6: post
# 需要导入模块: from blog.forms import CommentForm [as 别名]
# 或者: from blog.forms.CommentForm import save [as 别名]
def post(self, request):
a=request.POST.get('post')
print a
if request.GET:
print "get"
if request.POST:
print "post"
create_comment = CommentForm(request.POST)
if create_comment.is_valid():
create_comment.save()
return HttpResponseRedirect("/blog/"+str(a)+"/mainblog2/")
示例7: addcomment
# 需要导入模块: from blog.forms import CommentForm [as 别名]
# 或者: from blog.forms.CommentForm import save [as 别名]
def addcomment(request, article_id):
return_path = request.META.get('HTTP_REFERER', '/')
if request.POST and ("pause" not in request.session):
form = CommentForm(request.POST)
if form.is_valid():
comment = form.save(commit=False)
comment.comment_article = Article.objects.get(id=article_id)
form.save()
request.session.set_expiry(60) #ограничение ввода комментариев
request.session['pause'] = True
return redirect(return_path)
示例8: addcomment
# 需要导入模块: from blog.forms import CommentForm [as 别名]
# 或者: from blog.forms.CommentForm import save [as 别名]
def addcomment(request, article_id):
if request.POST and ("pause") not in request.session:
form = CommentForm(request.POST)
if form.is_valid():
comment = form.save(commit=False)
comment.comments_article = Article.objects.get(id=article_id)
form.save()
request.session.set_expiry(60)
request.session["pause"] = True
return redirect("/articles/get/%s/" % article_id)
示例9: comment_edit
# 需要导入模块: from blog.forms import CommentForm [as 别名]
# 或者: from blog.forms.CommentForm import save [as 别名]
def comment_edit(request, entry_pk, pk):
comment = get_object_or_404(Comment, pk=pk)
if request.method == "POST":
form = CommentForm(request.POST, instance=comment)
if form.is_valid():
form.save()
return redirect("blog.views.detail", entry_pk)
else:
form = CommentForm(instance=comment)
return render(request, "form.html", {"form": form})
示例10: comment_edit
# 需要导入模块: from blog.forms import CommentForm [as 别名]
# 或者: from blog.forms.CommentForm import save [as 别名]
def comment_edit(request, post_pk, pk):
# comment = Comment.objects.get(pk=pk)
comment = Comment.get_object_or_404(Comment, pk=pk)
if request.method == 'POST':
form = CommentForm(request.POST, instance=comment)
if form.is_valid():
form.save()
return redirect('blog,.post_detail', post_pk)
else:
form = CommentForm(instance=comment)
return render(request, 'blog/comment_form.html', {'form': form,
})
示例11: comment_new
# 需要导入模块: from blog.forms import CommentForm [as 别名]
# 或者: from blog.forms.CommentForm import save [as 别名]
def comment_new(request, post_pk):
if request.method == 'POST':
form = CommentForm(request.POST)
if form.is_valid():
form.save()
messages.debug(request, '새로운 댓글을 등록했습니다.')
return redirect('post_detail', post_pk)
else:
form = CommentForm()
return render(request, 'blog/comment_form.html', {'form':form,
})
示例12: comment_edit
# 需要导入模块: from blog.forms import CommentForm [as 别名]
# 或者: from blog.forms.CommentForm import save [as 别名]
def comment_edit(request, id, comment_id):
comment = get_object_or_404(Comment, id=comment_id)
if request.method == 'POST':
form = CommentForm(request.POST, request.FILES, instance=comment)
if form.is_valid():
form.save()
return redirect('blog:post_detail', id)
else:
form = CommentForm(instance=comment)
return render(request, 'blog/post_form.html', {
'form': form,
})
示例13: comment_form
# 需要导入模块: from blog.forms import CommentForm [as 别名]
# 或者: from blog.forms.CommentForm import save [as 别名]
def comment_form(request):
if request.method == 'POST':
form = CommentForm(request.POST)
if form.is_valid():
form.save(commit=True)
return index (request)
else:
print (form.errors)
else:
form = CommentForm()
return render(request, 'blog/comment_form.html', {'form':form})
示例14: comment_edit
# 需要导入模块: from blog.forms import CommentForm [as 别名]
# 或者: from blog.forms.CommentForm import save [as 别名]
def comment_edit(request, post_pk, pk):
# comment = Comment.objects.get(pk=pk)
# comment = get_object_or_404(Comment, pk=pk)
comment = request.instance
if request.method == "POST":
form = CommentForm(request.POST, instance=comment)
if form.is_valid():
form.save()
return redirect(comment.post)
else:
form = CommentForm(instance=comment)
return render(request, "blog/comment_form.html", {"form": form})
示例15: comment_edit
# 需要导入模块: from blog.forms import CommentForm [as 别名]
# 或者: from blog.forms.CommentForm import save [as 别名]
def comment_edit(request, post_pk, pk):
comment = get_object_or_404(Comment, pk=pk)
if request.method == 'POST':
form = CommentForm(request.POST, instance=comment)
if form.is_valid():
form.save()
messages.success(request, 'updated comment')
return redirect('blog.views.detail', post_pk)
else:
form = CommentForm(instance=comment)
return render(request, 'form.html', {
'form': form,
})