def delete_category(category_id): if category_id == 1: flash('You can not delete the default category.', 'warning') return redirect(url_for('blog.index')) category = Category.query.get_or_404(category_id) category.delete() flash('Category deleted', 'success') return redirect_back()
def set_comment(post_id): post = Post.query.get_or_404(post_id) if post.can_comment: post.can_comment = False flash('Comment disabled.', 'success') else: post.can_comment = True flash('Comment enabled.', 'success') db.session.commit() return redirect_back()
def login(): # http://127.0.0.1:5000/ 127.0.0.1:5000 /auth/login /auth/login?name=lmx # print(request.host_url, request.host, request.path, request.full_path) 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_back() flash('用户名或密码无效!', 'warning') else: flash('还没有创建管理员账户!', 'warning') return render_template('auth/login.html', form=form)
def delete_post(post_id): post = Post.query.get_or_404(post_id) db.session.delete(post) db.session.commit() flash('Post delete.', 'success') return redirect_back()
def delete_link(link_id): link = Link.query.get_or_404(link_id) db.session.delete(link) db.session.commit() flash('Link delete.', 'success') return redirect_back()
def delete_comment(comment_id): comment = Comment.query.get_or_404(comment_id) db.session.delete(comment) db.session.commit() flash('Comment deleted.', 'success') return redirect_back()
def approve_comment(comment_id): comment = Comment.query.get_or_404(comment_id) comment.reviewed = True db.session.commit() flash('Comment Published!', 'success') return redirect_back()
def logout(): logout_user() flash('退出成功!', 'info') return redirect_back()
def change_theme(theme_name): if theme_name not in current_app.config['BLUELOG_THEMES'].keys(): abort(404) response = make_response(redirect_back()) response.set_cookie('theme', theme_name, max_age=30 * 24 * 60 * 60) return response