page list 업데이트

This commit is contained in:
lbard
2026-01-05 16:59:20 +09:00
parent 7f8b372ed9
commit 8e759144bf
4 changed files with 134 additions and 7 deletions

28
app.py
View File

@@ -265,6 +265,34 @@ def delete_post(id):
else:
return jsonify(success=False, message='Could not delete the post'), 500
@app.route('/list')
@app.route('/list/<string:cate>')
def list(cate=None):
params = ()
cate_condition = ""
if cate:
cate_condition = "AND `category` = %s"
params = (cate,)
if 'user_info' in session: # 로그인된 사용자
query = f"""SELECT `id`, `title`, `category`, `thumbnail_img`, `contents`, `add_date`
FROM `blog`
WHERE `use_yn` = 'Y' {cate_condition}
ORDER BY `add_date` DESC;"""
else:
query = f"""SELECT `id`, `title`, `category`, `thumbnail_img`, `contents`, `add_date`
FROM `blog`
WHERE `use_yn` = 'Y' AND `public_yn` = 'Y' {cate_condition}
ORDER BY `add_date` DESC;"""
r, posts = sql_execute(query, params, is_data=True)
# 태그 제거 후 150자로 제한
for post in posts:
post['contents'] = remove_html_tags(post['contents'])[:150]
return render_template('list.html', posts=posts)
# ============================================
# 관리자 페이지