def apost(): ''' post: :param :文章的标题(title) 板块的id(id) 图片验证码(img_code) 文章内容(content) :return: code 200 json 发布成功 code 400 json 不存在该板块 code 403 json 传过来的数据有问题 ''' if request.method=='GET': boards=BoardModel.query.all() content={ 'boards':boards } return render_template('front/front_apost.html',**content) else: form=Post_verify(request.form) id=form.id.data title=form.title.data content=form.content.data if form.validate(): board=BoardModel.query.get(id) if board: post=PostModel(title=title,content=content) post.board=board post.author=g.front_user db.session.add(post) db.session.commit() return jsonify({'code':200,'message':'发布成功'}) else: return jsonify({'code':400,'message':'不存在该板块'}) else: message=form.errors.popitem()[1][0] return jsonify({'code':403,"message":message})
def create_test_post(): for x in range(1, 20): title = 'flask%s' % x content = '内容%s' % x board = BoardModel.query.filter_by(id=12).first() post = PostModel(title=title, content=content) post.board = board db.session.add(post) db.session.commit() print("恭喜!测试帖子添加成功")
def create_test_post(): for x in range(1, 205): title = '标题%s' % x content = '内容%s' % x board = BoardModel.query.first() author = FrontUser.query.first() post = PostModel(title=title, content=content) post.board = board post.author = author db.session.add(post) db.session.commit()
def create_test_post(): for x in range(1,20): title = '标题%s'%x content = '内容,%s'%x board = BoardModel.query.first() author = FrontUser.query.first() post = PostModel(title=title,content=content,board_id=board) post.author = author db.session.add(post) db.session.commit() print('恭喜!测试帖子添加成功!')
def create_test_post(): for x in range(1, 255): title = '标题{}'.format(x) content = '内容{}'.format(x) author = front_models.FrontUser.query.first() board = AddBoardModel.query.first() post = PostModel(title=title, content=content) post.board = board post.author = author db.session.add(post) db.session.commit() print('帖子添加成功')
def create_test_post(): for x in range(1, 200): title = "标题:%s" % x content = "内容:%s" % x board = BoardModel.query.first() author = FrontUser.query.first() post = PostModel(title=title, content=content) post.board = board post.author = author db.session.add(post) db.session.commit() print("测试帖子添加成功")
def create_test_post(): for x in range(1, 100): title = '我是标题%s' % x content = '我是内容,我的编号是%s' % x board = BoardModel.query.first() author = FrontUser.query.first() post = PostModel(title=title, content=content) post.board = board post.author = author db.session.add(post) db.session.commit() print('测试帖添加成功')
def create_test_posts(): for _ in range(0, 200): title = '标题%s' % _ board = random.choice(BoardModel.query.all()) content = '内容为:%s 板块为:%s' % (_, board.name) author = FrontUser.query.first() post = PostModel(title=title, content=content) post.board = board post.author = author db.session.add(post) db.session.commit() print('插入帖子测试成功!')
def create_test_post(): for i in range(351, 401): title = "帖子标题:{}".format(i) content = "帖子内容:{}".format(i) author = FrontUser.query.first() board = BoardModel.query.all()[9] post = PostModel(title=title, content=content) post.author = author post.board = board db.session.add(post) db.session.commit() print("所有帖子添加成功!")
def create_test_post(): for i in range(1, 200): title = f'标题 {i}' content = f"内容 {i}" board = BoardModel.query.first() author = FrontUser.query.first() post = PostModel(title=title, content=content) post.board = board post.author = author db.session.add(post) db.session.commit() print('Test Posts added successful!')
def create_test_post(): for x in range(1, 200): title = "标题%s" % x content = '内容%s' % x post = PostModel(title=title, content=content) author = FrontUser.query.first() board = BoardModel.query.first() post.author = author post.board = board db.session.add(post) db.session.commit() print('恭喜!测试帖子已经添加完成!')
def create_post(): for i in range(500): title = '百度公司' + str(i) content = '为了让更多开发者学习百度UNIT对话系统开发技能,8月30日起每周四14:00-15:30,百度与InfoQ联合推出了“ 从入门到实战 百度UNIT对话系统开发训练营”主题活动,百度的三位大咖级专家联合出席讲授三门线上课程,从UNIT对话系统的基本结构和功能入手,介绍UNIT核心模块和常用技术,以及UNIT平台底层机制,零起步零编程,教你快速完成对话系统的搭建和应用,掌握UNIT高级实用技巧,完成对话系统全套开发实践。' board = BoardModel.query.first() author = Front_user.query.first() post = PostModel(title=title, content=content) post.board = board post.author = author db.session.add(post) db.session.commit() print('创建成功')
def create_test_post(): for i in range(1, 205): title = f"标题{i}" content = f"内容,{i}" board = BoardModel.query.first() author = FrontUser.query.first() post = PostModel(title=title, content=content) post.board = board post.author = author db.session.add(post) db.session.commit() print('测试帖子添加成功')
def create_test_post(): for x in range(1,255): title = "标题%s" % x content = "内容%s" % x board = BoardModel.query.first() author = FrontUserModel.query.first() post = PostModel(title=title, content=content) post.board = board post.author = author db.session.add(post) db.session.commit() print("测试帖子添加成功!")
def create_test_post(): for x in range(1, 100): title = '标题{}'.format(x) content = '内容:{}'.format(x) board = BoardModel.query.first() author = FrontUser.query.first() post = PostModel(title=title, content=content) post.board = board post.author = author db.session.add(post) db.session.commit() print('测试帖子添加成功')
def create_test_post(): for i in range(1, 200): title = "测试%s" % i content = "内容%s" % i board = BoardModel.query.first() author = FrontUser.query.first() post = PostModel(title=title, content=content) post.board = board post.author = author db.session.add(post) db.session.commit() print("success")
def add_test_post(): for x in range(1, 201): title = '标题:%d' % x content = '内容:%d' % x board = BoardModel.query.first() author = FrontUser.query.first() post = PostModel(title=title, content=content) post.board = board post.author = author db.session.add(post) db.session.commit() print('添加第%d篇测试帖子成功!' % x) time.sleep(0.1)
def create_test_post(): for x in range(1, 200): title = '标题%s' % x content = '内容%s' % x post = PostModel(title=title, content=content) board = BannerModel.query.first() author = FrontUser.query.first() post.board = board post.author = author db.session.add(post) db.session.commit() print('恭喜!测试帖子添加成功')
def create_test_post(): numbers = [2, 3, 4, 5, 6] for x in range(1,205): title = '标题%s' % x content = '内容:%s' % x post = PostModel(title=title, content=content) board_id = random.choice(numbers) board = BoardModel.query.get(board_id) author = FrontUser.query.first() post.board = board post.author = author db.session.add(post) db.session.commit() print('测试帖子添加成功!')
def create_test_post(): for x in range(1, 200): title = "标题:%s" % x content = "内容:%s" % x post = PostModel(title=title, content=content) db.session.add(post) db.session.commit() print("帖子添加成功")
def apost(): ''' :return: ''' form = Verify_apost(request.form) if form.validate(): title = form.title.data content = form.content.data user = g.front_user post = PostModel(title=title, content=content) post.author = user db.session.add(post) db.session.commit() return jsonify({'code': 200, 'message': '发布成功'}) else: message = form.errors.popitem()[0][1] # 弹出表单验证失败第一条错误信息 return jsonify({'code': 412, 'message': message})
def apost(): if request.method == "GET": boards = BoardModel.query.all() return render_template("front/front_apost.html", boards=boards) else: form = AddPostForm(request.form) if form.validate(): title = form.title.data content = form.content.data boardId = form.boardId.data board = BoardModel.query.get(boardId) if not board: return restful.params_error(message="没有这个板块") post = PostModel(title=title, content=content) post.board = board post.author = current_user db.session.add(post) db.session.commit() return restful.success() else: return restful.params_error(form.get_error())
def apost(): if request.method == 'GET': boards = BoardModel.query.all() return render_template('front/front_apost.html', boards=boards) else: add_post_form = AddPostForm(request.form) if add_post_form.validate(): title = add_post_form.title.data content = add_post_form.content.data board_id = add_post_form.board_id.data board = BoardModel.query.get(board_id) if not board: return xjson.json_params_error(message='没有这个模版') post = PostModel(title=title, content=content) post.board = board post.author = g.front_user db.session.add(post) db.session.commit() return xjson.json_sucess() else: return xjson.json_params_error(message=add_post_form.get_error())
def create_test_post(): for x in range(1, 205): title = '标题%s' % x content = '内容:%s' % x board = BoardModel.query.first() author = FrontUser.query.first() post = PostModel(title=title, content=content, board=board, author=author) db.session.add(post) db.session.commit() print('恭喜,测试帖子添加完成')
def posts(count=50): count = int(count) for i in range(count): author_id = User.query.order_by(func.rand()).limit(1).first().id board_id = BoardModel.query.order_by(func.rand()).limit(1).first().id p = PostModel(title=fake.paragraph(1), content=fake.text(), create_time=fake.past_datetime(), author_id=author_id, board_id=board_id) db.session.add(p) db.session.commit() return '帖子数据生成成功!'
def apost(): # 帖子管理 if request.method == 'GET': boards = BoardMode.query.all() return render_template('front/front_apost.html', boards=boards) else: form = AddPostForm(request.form) if form.validate(): title = form.title.data content = form.content.data board_id = form.board_id.data board = BoardMode.query.get(board_id) if not board: return restful.params_error(message='板块不存在') post = PostModel(title=title, content=content) post.board = board post.author = g.front_user db.session.add(post) db.session.commit() return restful.success() else: return restful.params_error(message=form.get_error())
def add_post(): """添加帖子""" if request.method == 'GET': boards = BoardModel.query.all() context = {'boards': boards} return render_template('front/front_addpost.html', **context) else: form = AddPostForm(request.form) if form.validate(): title = form.title.data content = form.content.data board_id = form.board_id.data board = BoardModel.query.get(board_id) if not board: return restful.params_error(message='没有这个板块!') post = PostModel(title=title, content=content) post.board = board post.author = g.front_user db.session.add(post) db.session.commit() return restful.success() else: return restful.params_error(form.get_error())