Answer the question
In order to leave comments, you need to log in
How to implement likes in python with minimal js?
How to implement likes (backend in python, Flask) with minimal use of js?
Answer the question
In order to leave comments, you need to log in
It is not clear what likes are, well, let it be a rating system for any post. Create two plus and minus buttons. According to the smart, probably, it will be necessary to somehow make it into the form, and generally use the form flask, but let it be just like that. Connect jQuery to the page. Write a simple click handler for these buttons, so that when clicked, it sends a request to some of your endpoints, taking into account the votes for the post.
<body>
<span class="vote-button" data-action="upvote">+</span>
<span class="vote-button" data-action="downvote">-</span>
<script>
$(document).ready(function () {
$(".vote-button").click(function () {
var action = $(this).data("action");
$.ajax({
type: "POST",
url: "api/vote",
data: {
action: action,
postid: postid
}
});
});
});
</script>
</body>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question