所以这是我的数据库,评论工作正常,但我想添加回复:
CREATE TABLE comments (
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(50) NOT NULL,
text VARCHAR(300) NOT NULL,
post_id INT NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
这是我的烧瓶注释代码:
if 'logged_in' in session :
if (request.method == 'POST' and form.validate()):
comment = form.comment.data
cur = mysql.connection.cursor()
cur.execute("INSERT INTO comments (text, username, post_id) VALUES (%s, %s, %s)", (comment, session['username'], id))
mysql.connection.commit()
cur.close()
flash("Comment successful", 'success')
return redirect(url_for('index'))
我想知道实现评论回复的最佳方法是什么,谢谢;)