[Answered ]-How do you pass a variable from javascript to python (oTree) or django?

1👍

Using live pages seems to solve the issue.

https://otree.readthedocs.io/en/latest/live.html

So in Javascript:

 function sendTracker1() {
          liveSend({'which_char': 'char_1', 'value': tracker1})
      }

And in Python:

class MyPage(Page):
    form_model = 'player'

    @staticmethod
    def live_method(player, data):
        if data['which_char'] == 'char_1':
            player.timer_char1 = int(data['value'])


Leave a comment