Skip to content
Advertisement

ValueError could not convert string to float: ”

I’m having my app on heroku. I use timeme js to record user’s active time spend on the page, and use a hidden form to store the value into the database. Additionally, I’m using otree package to write my app. The following is the code I use:

models.py

JavaScript

views.py/pages.py in otree

JavaScript

html

JavaScript

The error

JavaScript

Is it because active_duration is empty? Will it help if I set blank=true, null=true for the forms?

I was assuming that every use would have value for the input. Also any ideas about why the input is empty? Could it be that the user used scripts to skip the page without visible fields? From the sentry error message, this happened to one user twice.

Advertisement

Answer

It is because you cannot cast an empty string to a float. You can do this instead though:

JavaScript

This will give you a “0” if data[“active_duration”] is empty, False, or None.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement