I write this simple example: I have a function x = 100*Math.random()
that print a number every t = 1000 ms
. Ok, it works.
My trouble is: how do I use/call an external python function (e.g. x = counter.py
) instead of x = 100*Math.random()
?
somepage.html
...
<script src="{% static 'jquery-1.11.2.js' %}"></script>
<script src="{% static 'js/contaBIS.js' %}"></script>
<button type="button" class="btn btn-success" id="start"> START </button>
<p id ="A"></p>
<p id ="B"></p>
...
contaBIS.js
$(document).ready(function() {
var x;
var t = 1000;
$('#start').click(function() {
$('#start')
.removeClass('btn-success')
.addClass('btn-warning disabled')
.text('WAIT');
var myVar=setInterval(function(){myTimer()},t);
function myTimer() {
document.getElementById("A").innerHTML="something's working ";
x = 100*Math.random(); //just an example
document.getElementById("B").innerHTML= x ;
}
});
counter.py
import time
z = 0
def prova(z):
while z < 10:
time.sleep(1)
z = z + 1
print(z) // I see z only on Eclipse console
return z
Ok, HERE I saw how to call an external function but I don't know how see its values on html. Do I have to write another view to do it? how?!
I look at print the value of a variable in Python/Django? but it is not good for me.