run.py 1.47 KB
Newer Older
1
import sqlite3
2
3
4
from flask import Flask, render_template
myapp = Flask(__name__)

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
dic = {"nname" : "Ford", "vname" : "Harrison", "gebjahr" : 1942}

def ausgabe():
    connect = sqlite3.connect("/website/test.db")
    cursor = connect.cursor()
    cursor.execute("SELECT COUNT(username) AS username FROM benutzer")
    #anzahl = int(str(cursor.fetchone()))
    a_user = []
    for i in range(0,4):
        cursor.execute("SELECT username FROM benutzer WHERE b_nr ="+ str(i))
        temp_name = cursor.fetchone()
        a_user.append(temp_name)
    print(type(a_user))
    return a_user

    user = cursor.fetchall()

def attribute():
    connect = sqlite3.connect("/website/test.db")
    cursor = connect.cursor()
    cursor.execute("SELECT username FROM benutzer")
    user = cursor.fetchall()
    print(type(user))
    username = []
    print(type(username))
    for person in user:
        username.append(person)
    i = 1
    return username

35
36
@myapp.route("/users")
def templ_test():
37
38
39
40
41
42
43
44
45
    return render_template('users.html', mydict = dic, list=[3,6,2,"drei",4,5], user_list = attribute(), userarray = ausgabe())

@myapp.route("/users/('mduscha',)")
def getduscha():
    connect = sqlite3.connect("/website/test.db")
    cursor = connect.cursor()
    cursor.execute("SELECT * FROM benutzer WHERE username = 'mduscha'")
    mduscha = cursor.fetchall()
    return str(mduscha)
46
47

if __name__ == '__main__':
48
49
50
    #print(dic)
    #ausgabe()
    #print(attribute())
51
    myapp.run(host = "0.0.0.0", debug = True)