Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -452,6 +452,26 @@ def submit_comment():
|
|
| 452 |
# Chuyển hướng lại trang bloglist
|
| 453 |
return redirect(url_for('bloglist'))
|
| 454 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 455 |
@app.route('/vechungtoi')
|
| 456 |
def vechungtoi():
|
| 457 |
conn = get_db_connection()
|
|
|
|
| 452 |
# Chuyển hướng lại trang bloglist
|
| 453 |
return redirect(url_for('bloglist'))
|
| 454 |
|
| 455 |
+
@app.route('/get_post/<int:post_id>')
|
| 456 |
+
def get_post(post_id):
|
| 457 |
+
conn = get_db_connection()
|
| 458 |
+
cursor = conn.cursor()
|
| 459 |
+
|
| 460 |
+
# Lấy bài viết
|
| 461 |
+
cursor.execute('SELECT * FROM posts WHERE id = ?', (post_id,))
|
| 462 |
+
post = cursor.fetchone()
|
| 463 |
+
if not post:
|
| 464 |
+
conn.close()
|
| 465 |
+
return jsonify({'error': 'Post not found'}), 404
|
| 466 |
+
post = dict(post)
|
| 467 |
+
|
| 468 |
+
# Lấy bình luận
|
| 469 |
+
cursor.execute('SELECT * FROM comments WHERE post_id = ? ORDER BY created_at DESC', (post_id,))
|
| 470 |
+
comments = [dict(row) for row in cursor.fetchall()]
|
| 471 |
+
|
| 472 |
+
conn.close()
|
| 473 |
+
return jsonify({'post': post, 'comments': comments})
|
| 474 |
+
|
| 475 |
@app.route('/vechungtoi')
|
| 476 |
def vechungtoi():
|
| 477 |
conn = get_db_connection()
|