def admin_index(): if request.method == 'GET': user = request.args.get('user') if user == app.config['LEIHUNAG_ADMIN_KEY']: categories = Category.query.all() return render_template('admin/index.html', categories=categories) else: return render_template('404.html') else: post = Post() post.title = request.values.get("title") post.path_name = request.values.get("path") post.category_id = request.values.get("category") post.author = request.values.get("author") category = Category.query.filter_by( category_id=post.category_id).first() category.post_num += 1 post.content = request.values.get("content") post.create_time = datetime.now() if exist_post(post.title): return '已经存在此博客' if exist_path_name(post.path_name): return '已经存在此路径的博客' db.session.add(post) db.session.flush() db.session.commit() return 'ok'