【发布时间】:2020-09-15 14:30:46
【问题描述】:
我的网站顶部有一个通知列表。
- 每个通知都可以是“已读”或“未读”。
- 每个通知都是一个可点击的锚元素,将用户带到与此通知相关的帖子。
目前我使用GET请求来处理用户的点击:
@webapp.route('/read')
@webapp.route('/read/<int:notification_id>')
@login_required
def read_notification(notification_id=None):
if notification_id is None:
return notifications.read(user=current_user)
fetched_notifications = notifications.get(current_user)
if notification is None:
return fail(404, 'Invalid notification ID.')
if notification.user.id != current_user.id:
return fail(403, "You aren't allowed to access this page.")
notifications.read(id_=notification_id)
return redirect(notification.action_url or '/exercises')
我对使用 GET 请求 /read 来更改通知状态有一种不好的感觉。另一方面,我不想使用 POST(或 PATCH),因为它需要我使用 <form>(语义错误)或 JavaScript(可能会导致用户体验滞后)。
还有更好的选择吗?
堆栈是 vanilla JavaScript 和 Flask (Python 3.8)。
【问题讨论】:
标签: javascript html http web flask