def create_user(): form = UserForm() if form.validate_on_submit(): form.create_user() flash('用户创建成功', 'success') return redirect(url_for('admin.users')) return render_template('admin/create_user.html', form=form)
def edit_user(user_id): user = User.query.get_or_404(user_id) form = UserForm(obj=user) if form.validate_on_submit(): form.update_user(user) flash('用户更新成功', 'success') return redirect(url_for('admin.users')) return render_template('admin/edit_user.html', form=form, user=user)
def add_user(): form = UserForm() if form.validate_on_submit(): form.add_user() flash('添加成功', 'success') return redirect(url_for('admin.users')) else: return render_template('admin/add_user.html', form=form)
def create_user(): form = UserForm() if form.validate_on_submit(): form.create_user() flash('用户创建成功', 'success') return redirect(url_for('admin.users')) #for field in form: #print(field(), field.label, field.label.text, field.data) return render_template('admin/create_user.html', form=form)
def edit_user(user_id): user = User.query.get_or_404(user_id) form = UserForm(obj=user) #for field in form: #print(field(), field.label, field.label.text, field.data) if form.validate_on_submit(): form.update_user(user) flash('用户更新成功', 'success') return redirect(url_for('admin.users')) return render_template('admin/edit_user.html', form=form, user=user)
def delete_user(user_id): user = User.query.get_or_404(user_id) form = UserForm(obj=user) form.delete_user(user) flash('用户删除成功', 'success') return redirect(url_for('admin.users'))