def post(self): key = self.request.get("key") logging.info(key) content = self.request.get("content") ip = self.request.remote_addr user_agent = escape(self.request.headers.get('User-Agent','Firefox')) if not content.strip(): return self.json({'error':u"内容不能为空"}) dis = Discussion.get_by_key_name(key) if dis is None: return self.json({'error':u"不要非法提交哦"}) if dis.is_closed: return self.json({'error':u"评论已经关闭"}) comment = Comment.new(self.user,dis,content,ip=ip,user_agent=user_agent) self.template_value['comment']=comment return self.json({'success':True,'comment':self.get_render("comment.html")})
def post(self): key = self.request.get("key") content = self.request.get("content") dis = get_or_404(Discussion.get_by_key_name,key) comment =Comment.new(self.user,dis,content) self.redirect(comment.url)