开发者

How do I make a simple HTML checkbox into a bool on Google App Engine?

开发者 https://www.devze.com 2023-02-13 07:58 出处:网络
Model Code: class Task(db.Model): complete = db.BooleanProperty(default=False) HTML Code: <input type=\"checkbox\" name=\"complete\" value=\"True\" />开发者_运维百科;

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

0

精彩评论

暂无评论...
验证码 换一张
取 消