本文整理汇总了Python中comments.models.Comment.chapter方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.chapter方法的具体用法?Python Comment.chapter怎么用?Python Comment.chapter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类comments.models.Comment
的用法示例。
在下文中一共展示了Comment.chapter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_comment
# 需要导入模块: from comments.models import Comment [as 别名]
# 或者: from comments.models.Comment import chapter [as 别名]
def new_comment(request):
# saving the poted comment
if request.method == 'POST':
form = CommentForm(request.POST)
if form.is_valid():
comment = Comment()
comment.book = form.cleaned_data.get("book")
comment.chapter = form.cleaned_data.get("chapter")
comment.example = form.cleaned_data.get("example")
comment.page = form.cleaned_data.get("page")
comment.title = form.cleaned_data.get("title")
comment.body = form.cleaned_data.get("body")
comment.email = form.cleaned_data.get("email", "Anonymous")
comment.save()
return HttpResponseRedirect(
'/comments/get/?book={0}&chapter={1}&example={2}&page={3}'.format(
comment.book, comment.chapter, comment.example, comment.page
)
)
else:
book = request.POST.get('book', '')
chapter = request.POST.get('chapter', '')
example = request.POST.get('example', '')
page = request.POST.get('page', '')
return HttpResponseRedirect(
'/comments/new/?book={0}&chapter={1}&example={2}&page={3}'.format(
book, chapter, example, page
)
)
# retriving comment parameters
book = request.GET.get('book', '')
chapter = request.GET.get('chapter', '')
example = request.GET.get('example', '')
page = request.GET.get('page', '')
initial_values = {
'book': book,
'chapter': chapter,
'example': example,
'page': page
}
form = CommentForm(initial = initial_values)
context = {
'form': form,
'book': book,
'chapter': chapter,
'example': example,
'page': page
}
context.update(csrf(request))
return render(request, 'comments/new_comment.html', context)