本文整理汇总了Python中blog.forms.CommentForm.get_parent方法的典型用法代码示例。如果您正苦于以下问题:Python CommentForm.get_parent方法的具体用法?Python CommentForm.get_parent怎么用?Python CommentForm.get_parent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.forms.CommentForm
的用法示例。
在下文中一共展示了CommentForm.get_parent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ArticleView
# 需要导入模块: from blog.forms import CommentForm [as 别名]
# 或者: from blog.forms.CommentForm import get_parent [as 别名]
def ArticleView(request, article_id):
article_id = int(article_id)
try:
article = Article.objects.get(pk=article_id)
if article.published:
if request.POST:
if not article.comment_allowed:
return HttpResponseForbidden()
form = CommentForm(request.POST)
if form.is_valid():
name = form.cleaned_data.get("name")
email = form.cleaned_data.get("email")
url = form.cleaned_data.get("url")
content = form.cleaned_data.get("content")
parent = form.get_parent()
ipaddr = (
request.META.get("HTTP_X_REAL_IP") or
request.META.get("HTTP_X_FORWARDED_FOR")
) or "127.0.0.1"
useragent = request.META.get("HTTP_USER_AGENT")
response = request.POST.get('g-recaptcha-response')
if validate_user(response, ipaddr):
Comment.objects.create(
article=article,
name=name,
email=email,
url=url,
ipaddr=ipaddr,
useragent=useragent,
content=content,
parent=parent)
else:
form = CommentForm()
comments = Comment.objects.filter(article=article)
context = RequestContext(
request,
{"article": article, "comments": comments, "form": form})
return render_to_response(
"blog/article.html",
{'sitekey': settings.RECAPTCHA_SITE_KEY},
context_instance=context)
else:
return HttpResponseNotFound()
except Article.DoesNotExist:
return HttpResponseNotFound()