methods = set(item.upper() for item in methods)
@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})
<a data-id="{{comment.id}}" class="like-button">Like</a>
$('.like-button').onclick(
...
//Post запрос по url, из data-id
$.ajax({
type: 'POST',
url: "/comment/"+data-id+"/like",
data: data
});
// если удался меняем innerhtml
s = open('my.json').read()
data = json.loads(s)
print json.dumps(data, ensure_ascii=False, indent=4)
import json
listok = {'привет': 'медвед'}
data = json.dumps(listok)
print('Json: %s' % data)
new_obj = json.loads(data)
print('Python obj: %s' % new_obj)
Json: {"\u043f\u0440\u0438\u0432\u0435\u0442": "\u043c\u0435\u0434\u0432\u0435\u0434"}
Python obj: {'привет': 'медвед'}
#!/usr/bin/python
# -*- coding: utf-8 -*-
import json
listok = {'привет': 'медвед'}
data = json.dumps(listok)
print 'Json: %s' % data
new_obj = json.loads(data)
print('Python obj: %s' % new_obj)
for key in new_obj:
print key, new_obj[key]
Json: {"\u043f\u0440\u0438\u0432\u0435\u0442": "\u043c\u0435\u0434\u0432\u0435\u0434"}
Python obj: {u'\u043f\u0440\u0438\u0432\u0435\u0442': u'\u043c\u0435\u0434\u0432\u0435\u0434'}
привет медвед