Z
Z
zedzew2015-05-26 15:08:43
Flask
zedzew, 2015-05-26 15:08:43

How to add a counter using Flask?

How to add a counter using Flask? Maybe there are useful articles or someone knows an example?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Abiduev, 2015-05-27
@gunlinux

If by clever flask-redis, and very little js/jquery
code Dig in that direction. In principle, you can also sql

@app.route('/comment/<int:id>/like', methods=["POST"])
@login_required
def comment_like(id):
    comment = Comment.query.get_or_404(id)
    comment.like += 1
    db.session.add(comment)
    db.session.commit()
    return jsonify({'likes': comment.like})

Well, you make buttons
And you hang up the handler,
$('.like-button').onclick(
  ...
  //Post запрос по url, из  data-id
$.ajax({
  type: 'POST',
  url: "/comment/"+data-id+"/like",
  data: data
});
 // если удался меняем innerhtml

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question