def postdetails(year, month, id): lenth = 0 comments = Comment.query.filter(Comment.Post_Id == id).order_by( Comment.Id.desc()).all() lenth = len(comments) content = "" posts = Post.query.filter(Post.User_Id == 1, Post.Id == id).first() post_file = posts.Content_Name basepath = os.path.abspath(os.path.dirname(__file__)) # 当前文件所在目录 parentdir = os.path.dirname(basepath) # 父级目录 datetimes = posts.Publish_Date # now = str(datetimes.year)+"-"+str(datetimes.month)+"-"+str(datetimes.day) # newdirname = now + "_" + posts.Title if post_file != None: post_file_url = os.path.join(parentdir, 'static/Upload_Files/article', posts.Dir_Name, secure_filename(post_file)) content = switch_html(post_file_url) if request.method == "POST": # 判断称呼是否合法 if request.form.get( "nickname") == u"落风" and g.current_user_name != u"落风": flash(u"评论的称呼已被博主使用了哦,换个称呼重试吧! -_-||", category="warning") return render_template('Post_Details.html', posts=posts, content=content, lenth=lenth, comments=comments, title=posts.Title) commentforsql = Comment() commentforsql.Name = request.form.get("nickname") commentforsql.Email = request.form.get("email") commentforsql.text = request.form.get("leavemessage") commentforsql.Post_Id = id db.session.add(commentforsql) db.session.commit() comments = Comment.query.filter(Comment.Post_Id == id).order_by( Comment.Id.desc()).all() lenth = len(comments) return render_template('Post_Details.html', posts=posts, content=content, lenth=lenth, comments=comments, title=posts.Title) return render_template('Post_Details.html', posts=posts, content=content, lenth=lenth, comments=comments, title=posts.Title)