def make_comment(): '''评论单本小说, 需要登录''' try: novel = Novel.query.get(novel_id) except Exception as e: current_app.logger.debug(e) return jsonify(re_code=RET.DBERR, msg='查询小说失败') if not novel: return jsonify(re_code=RET.NODATA, msg='小说不存在') if not g.user_id: return jsonify(re_code=RET.SESSIONERR, msg='用户未登录') comment = request.json.get('comment') user_id = g.user_id timestamp = datetime.utcnow() comment = Comment() comment.timestamp = timestamp comment.content = comment comment.audienc_id = user_id comment.novel_id = novel_id try: db.session.add(comment) db.session.commit() except Exception as e: current_app.logger.debug(e) db.session.rollback() return jsonify(re_code=RET.DBERR, msg='评论发表失败') else: return jsonify(re_code=RET.OK, msg='评论发表成功')