Reputation: 6601
I have a notification list at the top of my website.
Currently I use GET request to handle the user's click:
@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')
I have a bad feeling about using a GET request to /read
in order to change the state of the notification. On the other hand, I don't want to use POST (or PATCH), 'cause it will require me to use <form>
(semantically wrong) or JavaScript (may create a laggy user experience).
Is there any better option?
The stack is vanilla JavaScript and Flask (Python 3.8).
Upvotes: 0
Views: 145
Reputation: 754
You can actually redirect with the POST
method by using code=307
. For more information, you can read this
return redirect(notification.action_url or '/exercises', code=307)
Upvotes: 1