Answer the question
In order to leave comments, you need to log in
How to create likes system without django registration?
Greetings. Submit on ajax click:
$('.plus{{ server.id }}').on('click', function() {
var data_plus = {
id: {{server.id}},
move: '+'
}
$.ajax({
url: '/add_voice/',
dataType: 'json',
data: data_plus,
success: function(response) {
$('.voices{{ server.id }} b').html(response['voices_count'])
}
});
})
$('.minus{{ server.id }}').on('click', function() {
var data_minus = {
id: {{server.id}},
move: '-'
}
$.ajax({
url: '/add_voice/',
dataType: 'json',
data: data_minus,
success: function(response) {
$('.voices{{ server.id }} b').html(response['voices_count'])
}
});
})
def add_voice(request):
id = request.GET.get('id')
move = request.GET.get('move')
server = Server.objects.get(id=id)
ip = get_client_ip(request)
if move == '+':
server.voices += 1
server.save()
if move == '-':
server.voices -= 1
server.save()
voices_count = server.voices
response_data = {
'voices_count': voices_count
}
return JsonResponse(response_data)
Answer the question
In order to leave comments, you need to log in
The options are:
The last 2 points are more convenient to do using JS. As you understand, they are not reliable at all, because cookies and localStorage are stored in the user's browser and nothing prevents them from being deleted.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question