def send_posts(): form = SendPosts() if form.validate_on_submit(): if current_user.is_authenticated: p = Posts(title=form.articletitle.data, article=form.article.data, user=current_user, timestamp=datetime.utcnow() + timedelta(hours=8)) print(p.timestamp) p.save() flash('发表成功') cache.clear() #因为数据库更新,页面也需要更新,所以需要清除所有缓存 return redirect(url_for('posts.send_posts')) else: print(1) flash('您还没登录') return redirect(url_for('user.login')) if not current_user.is_authenticated: print(2) flash('您还没登录 请登录后发表') c = Course.query.filter_by(pid=0) c1 = Course.query.filter(and_(Course.path.endswith(','), Course.pid != 0)) c2 = Course.query.filter( and_(not_(Course.path.endswith(',')), Course.pid != 0)) return render_template('posts/send_posts.html', form=form, course=c, course1=c1, course2=c2)
def edit_posts(pid): form = SendPosts() # 实例化表单 p = Posts.query.get(pid) # 根据博客id 查询 ctgs = Categorys.query.all() if not p: flash('该博客不存在') return redirect(url_for('owncenter.posts_manager')) if form.validate_on_submit(): # md格式 article = request.form['article'] # 得到所选的分类值 ctgs = request.form['ctgs'] tags = Categorys.query.filter_by(categorys=ctgs).first() # 图片上传 img = request.files.get('img') # 获取上传对象 ex = os.path.splitext(img.filename)[1] filename = datetime.now().strftime('%Y%m%d%H%M%S') + ex file = img.stream.read() qiniu_store.save(file, filename) p.title = form.title.data p.article = article p.img = qiniu_store.url(filename) p.tags = [tags] p.save() flash('博客更新成功') return redirect(url_for('owncenter.posts_manager')) form.title.data = p.title form.article.data = p.article return render_template('owncenter/edit_posts.html', form=form, ctgs=ctgs)
def send_posts(): form = SendPosts() ctgs = Categorys.query.all() # 判断登录后在进行发表 if not current_user.is_authenticated: flash('您还没有登录 请登录后再发表') if current_user.id == 1: if form.validate_on_submit(): # md格式 article = request.form['article'] ctgs = request.form['ctgs'] tags = Categorys.query.filter_by(categorys=ctgs).first() # 图片上传 img = request.files.get('img') # 获取上传对象 ex = os.path.splitext(img.filename)[1] filename = datetime.now().strftime('%Y%m%d%H%M%S') + ex file = img.stream.read() qiniu_store.save(file, filename) post = Posts(title=form.title.data, user=current_user, article=article, img=qiniu_store.url(filename), tags=[tags]) post.save() flash('博客发表成功') return redirect(url_for('main.index')) else: flash('您没有发表博客的权限!') return redirect(url_for('main.index')) return render_template('posts/send_posts.html', form=form, ctgs=ctgs)
def send_posts(): form = SendPosts() if form.validate_on_submit(): print(form.article.data) p = Posts(title=form.articletitle.data, article=form.article.data, user=current_user) p.save() return render_template('posts/send_posts.html', form=form)
def send_posts(): form = SendPosts() # 判断登录后在进行发表 if not current_user.is_authenticated: flash('您还没有登录 请登录后在发表') elif form.validate_on_submit(): # 保存发表博客的数据 Posts(title=form.title.data, article=form.article.data, user=current_user).save() flash('博客发表成功') return redirect(url_for('main.index')) return render_template('posts/send_posts.html', form=form)
def edit_posts(pid): form = SendPosts() # 实例化表单 p = Posts.query.get(pid) # 根据博客id 查询 if not p: flash('该博客不存在') return redirect(url_for('owncenter.posts_manager')) if form.validate_on_submit(): p.title = form.title.data # 进行数据的存储 p.article = form.article.data p.save() flash('博客更新成功') return redirect(url_for('owncenter.posts_manager')) form.title.data = p.title form.article.data = p.article return render_template('owncenter/edit_posts.html', form=form)
def send_posts(): form = SendPosts() if form.validate_on_submit(): if current_user.is_authenticated: p = Posts(title=form.articletitle.data, article=form.article.data, user=current_user) p.save() flash('发表成功') return redirect(url_for('posts.send_posts')) else: flash('您还没有登录,请先登录再发表') if not current_user.is_authenticated: flash('您还没有登录,请登录后再发表') return render_template('posts/send_posts.html', form=form)