How do I make a simple HTML checkbox into a bool on 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: Property complete must be a bool
How should this be done?
Since unchecked checkboxes are not sent as a parameter...
task.complete = self.request.get('complete') != ''
You can use the type() funktion to check the tape of 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 different methods
精彩评论