D
D
Domohod2021-05-06 21:16:33
JavaScript
Domohod, 2021-05-06 21:16:33

How to store click count in django server?

Django project.

There is a button, clicks on it are shown in the paragraph:

<button  class="button_p" onclick="doCount()"><h1 style="color: #331c2a">Choose</h1></button>
<p>Всего попыток: <span id="count"></span></p>


here is the js code:
function doCount() {
  var count = document.getElementById('count');
  count.innerHTML = +count.innerHTML + 1;
}


The problem is that when the page is refreshed, the number of clicks disappears.
How to make sure that this number is preserved?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey Yarkov, 2021-05-06
@yarkov

Send to the server every click

I
Ivan Demianov, 2021-05-09
@Vanushka1102

def function(request):
return JsonResponge({"clic":mymodel.objects.last().clic})
def someinput(request,message):
m = mymodel(clic=message)
m.save()
Make the appropriate urls, and fetch url someinput on button click, and fetch function on page load, and model mymodel with clic (int) field

Y
Yupiter7575, 2021-05-06
@yupiter7575

Alternatively, a form will be sent when clicked. Or the user's response from above

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question