def add_people(request): people = People() people.name = '后羿%d' % random.randrange(100) people.sex = '男' people.save() card = Card() card.num = random.randrange(100000, 200000) card.cid = people card.save() return HttpResponse('添加成功')
def import_excels(): form_data = [] exceldir = "/Users/lishun/PycharmProjects/solution_project/app/static/video/people.xlsx" bk = open_workbook(exceldir, encoding_override="utf-8") try: sh = bk.sheets()[0] except: print("no sheet in %s named sheet1" % exceldir) else: nrows = sh.nrows for i in range(1, nrows): row_data = sh.row_values(i) people = People() people.id = row_data[0] people.name = row_data[1] people.age = row_data[2] form_data.append(row_data) # db.session.add(people) # db.session.commit() return render_template('admin/import_device.html', form_data=form_data)