本文整理汇总了Python中models.Person.create_table方法的典型用法代码示例。如果您正苦于以下问题:Python Person.create_table方法的具体用法?Python Person.create_table怎么用?Python Person.create_table使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Person
的用法示例。
在下文中一共展示了Person.create_table方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from models import Person [as 别名]
# 或者: from models.Person import create_table [as 别名]
def main(argv):
db.connect()
try:
Person.drop_table()
except sqlite3.OperationalError:
pass
Person.create_table()
with open(argv[1]) as f:
csv_file = DictReader(f)
for line in csv_file:
attrs = {
'trac_id': float(line['TRAC Assigned Identifier for Individual'].strip()),
'nationality': line['Nationality'].strip(),
'gender': line['Gender'].strip(),
}
try:
person = Person.select().where((Person.trac_id == attrs['trac_id']) & (Person.nationality == attrs['nationality'])).get()
except Person.DoesNotExist:
person = Person.create(**attrs)
示例2: redirect
# 需要导入模块: from models import Person [as 别名]
# 或者: from models.Person import create_table [as 别名]
person.save()
return redirect(url_for('index'))
return render_template('edit.html', form=form, person=person)
@app.route('/delete/<int:id>', methods=['GET', 'POST'], endpoint="delete")
def delete(id):
try:
person = Person.get(Person.id == id)
except Person.DoesNotExist:
abort(404)
if request.method == 'POST':
person.delete_instance()
if request.is_xhr:
return jsonify(success=True, person=person.serialize())
else:
return redirect(url_for('index'))
return render_template('delete.html', person=person)
@app.errorhandler(404)
def page_not_found(error):
return render_template('404.html'), 404
if __name__ == "__main__":
Person.create_table(fail_silently=True)
app.run()