From d7effe429a4d74f0acc133fa69e737ea7ddf51ef Mon Sep 17 00:00:00 2001 From: jakobsn Date: Thu, 3 Oct 2019 17:37:16 +0200 Subject: [PATCH] using good old mysql queries no longer throwing error. --- mysql/sql/init.sql | 3 ++- src/app/main.py | 21 +++++++++------------ src/app/templates/index.html | 4 ++-- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/mysql/sql/init.sql b/mysql/sql/init.sql index c8aa74e..51bb84e 100644 --- a/mysql/sql/init.sql +++ b/mysql/sql/init.sql @@ -8,4 +8,5 @@ CREATE TABLE `db`.`users` ( insert into users values (0, "admin", "password"); insert into users values (1, "bernt", "inge"); - +CREATE USER 'root'@'10.5.0.6' IDENTIFIED BY 'root'; +GRANT ALL PRIVILEGES ON db.* TO 'root'@'10.5.0.6'; diff --git a/src/app/main.py b/src/app/main.py index 4e27d60..d11190d 100644 --- a/src/app/main.py +++ b/src/app/main.py @@ -1,21 +1,15 @@ import web from web import form - +import mysql.connector urls = ( '/', 'index' ) -# Connect to database -db = web.database( - dbn="mysql", - host='10.5.0.5', - port=3306, - user='root', - pw='root', - db='db' -) - +db2 = mysql.connector.connect(user='root', password='root', + host='10.5.0.5', + database='db') + # Initialize application using the web py framework app = web.application(urls, globals()) @@ -32,7 +26,10 @@ class index(): def GET(self): - friends = db.select('users') + cursor = db2.cursor() + query = ("SELECT userid, username from users") + cursor.execute(query) + friends = cursor.fetchall() return render.index(login_form, friends) diff --git a/src/app/templates/index.html b/src/app/templates/index.html index 6604d0b..75f8fbd 100644 --- a/src/app/templates/index.html +++ b/src/app/templates/index.html @@ -21,8 +21,8 @@ $def with (login_form, friends)

Registered friends:

\ No newline at end of file