Exemple #1
0
def showdata():

    connection =  conn()
    cursor = connection.cursor()
    cursor.execute("SELECT id, firstName, lastName, phone FROM users")
    rows = cursor.fetchall()
    cursor.close()

    objects_list = []
    for row in rows:
        d = collections.OrderedDict()
        d['id'] = row[0]
        d['firstName'] = row[1]
        d['lastName'] = row[2]
        d['phone'] = row[3]
        objects_list.append(d)
    return render_template('showdata/index.html', dados=objects_list)
Exemple #2
0
def insertdata():
    if request.method == 'POST':
        form = LoginForm()
        if form.validate_on_submit():
            fields = ('firstName', 'lastName', 'phone')
            firstName = str(form.firstName.data)
            lastName = str(form.lastName.data)
            phone = str(form.phone.data)
            
            connection =  conn()
            cursor = connection.cursor()
            cursor.execute("INSERT INTO users (firstName, lastName, phone) VALUES ('%s', '%s', '%s')" % (firstName, lastName, phone))
            connection.commit()
            
            flash('Dados inseridos com sucesso! First Name = "%s", Last Name = "%s", Phone = "%s"' % (firstName, lastName, phone))
            return redirect('/insertdata')
        return render_template('insertdata/index.html', form=form)
    return render_template('insertdata/index.html', form=LoginForm())