def add_section(title): if current_user.is_adminenticated: return redirect(url_for('admin.admin')) if not current_user.real_name: flash(_('完善资料后再试')) return redirect(url_for('admin.index')) if not current_user.is_authed: flash(_('用户信息审核中, 稍后再试')) return redirect(url_for('admin.index')) post = Post.query.filter_by(title=title).first_or_404() if not current_user == post.author: abort(400) form = SectForm() if form.validate_on_submit(): sect = Section(title=form.title.data, body=form.body.data, author=current_user, parent=post) #_file form.video.data.filename = sect.set_video(form.video.data.filename) filename = videos.save(form.video.data) file_url = videos.url(filename) sect.set_video(file_url.split('/')[-1], token=True) db.session.add(post) db.session.commit() flash(_('单元添加申请已提交')) return redirect(url_for('admin.index')) return render_template('admin/section.html', title=_('单元添加'), post=post, form=form)