def delete_post(post_id): post = Post.query.get_or_404(post_id) post.delete() # db.session.delete(post) # db.session.commit() flash('文章已删除', 'success') return redirect_next()
def change_theme(theme_name): if theme_name not in current_app.config['BRBLOG_THEMES'].keys(): abort(404) response = make_response(redirect_next()) response.set_cookie('theme', theme_name, max_age=30 * 24 * 60 * 60) return response
def delete_comment(comment_id): comment = Comment.query.get_or_404(comment_id) # db.session.delete(comment) comment.delete() db.session.commit() flash('已成功删除', 'success') return redirect_next()
def set_comment(post_id): post = Post.query.get_or_404(post_id) if post.can_comment: post.can_comment = False flash('评论已关闭.', 'success') else: post.can_comment = True flash('评论已打开', 'success') db.session.commit() return redirect_next()
def login(): if current_user.is_authenticated: return redirect(url_for('blog.index')) form = LoginForm() if form.validate_on_submit(): username = form.username.data password = form.password.data remember = form.remember.data admin = Admin.query.first() if admin: if username == admin.username and admin.validate_password( password): login_user(admin, remember) flash('欢迎回来', 'info') return redirect_next() flash('用户名或密码错误', 'warning') else: flash('还没有生成账户', 'warning') return render_template('auth/login.html', form=form)
def approve_comment(comment_id): comment = Comment.query.get_or_404(comment_id) comment.reviewed = True db.session.commit() flash('已审核通过', 'success') return redirect_next()
def logout(): logout_user() flash('注销成功.', 'info') return redirect_next()