Skip to content
Advertisement

Django Error – unsupported operand type(s) for -: ‘str’ and ‘int’

I have a Django code that must do some math, but I continuously get the following error:

unsupported operand type(s) for -: ‘str’ and ‘int’

Here is the code:

JavaScript

Here is also the URL where I want to get “nor” from:

http://localhost:8000/mechanical/?nor=4&mc=yes&repaired=no&submit=Submit

Advertisement

Answer

Query string params are always string, you need to convert them to desired type. Here you need to convert string to int.

JavaScript

You can try-catch block around your type conversion to handle other exceptions.

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