Python 如何访问模型&x27;onclick事件中的s字段(django)

Python 如何访问模型&x27;onclick事件中的s字段(django),python,django,Python,Django,我不是英语使用者,所以我的英语不会很好 我在学django 我想在单击模板中的按钮时访问模型的字段 <button type="button" onclick="{% post.like+=1 %}">1따봉!</button> 추천 수 : {{ post.like }} 这是模板中的相关部分 <button type="button" onclick="{% post.like+=1 %}">1따봉!</button> 추천 수 : {{ p

我不是英语使用者,所以我的英语不会很好

我在学django

我想在单击模板中的按钮时访问模型的字段

<button type="button" onclick="{% post.like+=1 %}">1따봉!</button> 추천 수 : {{ post.like }}
这是模板中的相关部分

<button type="button" onclick="{% post.like+=1 %}">1따봉!</button> 추천 수 : {{ post.like }}
1따봉! 추천 수 : {{post.like}}
当我点击按钮时,我希望将like计数增加1


如何才能做到这一点?

您可以使用jquery更轻松地做到这一点

<button id="buttonLike" data-like="{{ post.like }}" type="button">{{ post.like }}</button>
$(function() {
        $('#buttonLike').on('click', function() {
            var val = parseInt($(this).data('like'));
            val += 1;
            $(this).data('like', val);
            $(this).val(val);
            // Do some ajax operations to update the django model
        });
    });
{{post.like}
$(函数(){
$('#按钮状')。在('单击',函数()上){
var val=parseInt($(this.data('like'));
val+=1;
$(this).data('like',val);
$(this).val(val);
//执行一些ajax操作来更新django模型
});
});

您可以使用jquery更轻松地完成这项工作

<button id="buttonLike" data-like="{{ post.like }}" type="button">{{ post.like }}</button>
$(function() {
        $('#buttonLike').on('click', function() {
            var val = parseInt($(this).data('like'));
            val += 1;
            $(this).data('like', val);
            $(this).val(val);
            // Do some ajax operations to update the django model
        });
    });
{{post.like}
$(函数(){
$('#按钮状')。在('单击',函数()上){
var val=parseInt($(this.data('like'));
val+=1;
$(this).data('like',val);
$(this).val(val);
//执行一些ajax操作来更新django模型
});
});

您使用的是jQuery还是核心Javascript?我可以使用jQuery和Javascript,但现在我没有使用它们。您使用的是jQuery还是核心Javascript?我可以使用jQuery和Javascript,但现在我没有使用它们。