本文整理汇总了Python中blog.models.Comment.UserName方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.UserName方法的具体用法?Python Comment.UserName怎么用?Python Comment.UserName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.Comment
的用法示例。
在下文中一共展示了Comment.UserName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: saveComment
# 需要导入模块: from blog.models import Comment [as 别名]
# 或者: from blog.models.Comment import UserName [as 别名]
def saveComment(request):
userid = request.session.get('userid', '')
if userid == '':
return HttpResponseRedirect('/index')
permission = request.session.get('permission', '')
if permission < 1:
return HttpResponseRedirect('/index')
commentText = request.POST['commentText']
passageID = int(request.META['HTTP_REFERER'].split('/passage/')[1])
passageObj = Passage.objects.get(id = passageID)
passageObj.CommentTimes += 1
passageObj.save()
commentObj = Comment()
userObj = User.objects.get(id = userid)
commentObj.UserID = userObj
commentObj.UserName = userObj.UserName
commentObj.PassageID = passageObj
commentObj.Time = datetime.now()
commentObj.Content = commentText
commentObj.save()
commentObjLs = Comment.objects.filter(PassageID = passageID)[0:10]
t = get_template('moreComment.html')
c = Context({'commentObjLs':commentObjLs})
html = t.render(c)
#return HttpResponse('Hello')
jsonObject = json.dumps({'html':html, 'commentCount':passageObj.CommentTimes},ensure_ascii = False)
#加上ensure_ascii = False,就可以保持utf8的编码,不会被转成unicode
return HttpResponse(jsonObject,content_type="application/json")