How to make a simple HTML checkbox in bool in Google App Engine?

Model Code:

class Task(db.Model): complete = db.BooleanProperty(default=False) 

HTML code:

 <input type="checkbox" name="complete" value="True" /> 

Database:

 task = Task() task.complete = self.request.get('complete') task.put() 

This returns an error:

BadValueError: the complete property must be bool

How to do it?

+4
source share
2 answers

Since unchecked flags are not sent as a parameter ...

 task.complete = self.request.get('complete') != '' 
+5
source

The type () function can be used to check the tape self.request.get('complete') I would suggest that self.request.get('complete') returns "True", but as a String , so you should convert it to boolean . Here is a list of the various methods.

0
source

Source: https://habr.com/ru/post/1341393/


All Articles