Selaa lähdekoodia

using good old mysql queries no longer throwing error.

https
jakobsn 6 vuotta sitten
vanhempi
commit
d7effe429a
3 muutettua tiedostoa jossa 13 lisäystä ja 15 poistoa
  1. +2
    -1
      mysql/sql/init.sql
  2. +9
    -12
      src/app/main.py
  3. +2
    -2
      src/app/templates/index.html

+ 2
- 1
mysql/sql/init.sql Näytä tiedosto

@@ -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';

+ 9
- 12
src/app/main.py Näytä tiedosto

@@ -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)




+ 2
- 2
src/app/templates/index.html Näytä tiedosto

@@ -21,8 +21,8 @@ $def with (login_form, friends)

<h3>Registered friends:</h3>
<ul>
$for name in friends:
<li id="t$name.userid">$name.username</li>
$for user in friends:
<li id="user[0]">$user[1]</li>
</ul>

</body>

Loading…
Peruuta
Tallenna