def create_post(): post = Post() try: data = request.get_data() data = json.loads(data) post.title = data['title'] post.content = data['content'] post.category_id = data['category_id'] tags = data['tags'] post.region = data['region'] post.image_header_id = data['image_header_id'] except Exception: raise ServiceException(ErrorCode.PARAM_ERROR, 'param error') tag_ids = [] if tags is not None and tags != '': tags = tags.split(",") for tag_name in tags: try: tag = GroupService.get_tag_by_name(tag_name) except ServiceException: tag = GroupService.insert_tag(tag_name) tag_ids.append(str(tag.id)) post.tag_ids = ",".join(tag_ids) post = PostService.insert_post(post) return jsonify(json_resp(data=model2dict(post)))