run.py 1.3 KB
Newer Older
1
2
3
4
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
35
36
37
38
39
40
41
42
43
#!/usr/bin/python3
from flask import Flask, render_template, request
import sqlite3

databse = "test.db"
app = Flask(__name__)
name = str(app.route)


def all_user():
    connection = sqlite3.connect("test.db")
    cursor = connection.cursor()       
    connection.row_factory = sqlite3.Row
    cursor.execute("SELECT username FROM benutzer;")
    all_i = cursor.fetchall()
    return all_i

def one_user(name):
    connection = sqlite3.connect("test.db")
    cursor = connection.cursor()
    connection.row_factory = sqlite3.Row       
    cursor.execute("SELECT * FROM benutzer WHERE username = '" + name + "';")
    user_data = cursor.fetchone()
    return user_data

def get_name(name):
    connection = sqlite3.connect("test.db")
    cursor = connection.cursor()
    connection.row_factory = sqlite3.Row       
    cursor.execute("SELECT username FROM benutzer WHERE username = '" + name + "';")
    user_id = cursor.fetchone()
    return user_id

@app.route('/user', methods=['GET','POST'])
def username_ausgabe():
    return render_template("users.html", all_ids = all_user())

@app.route('/user/<username>', methods=['GET','POST'])
def user_ausgabe(username):
    return render_template("user.html", user = one_user(username), name=get_name(username))

if __name__ == '__main__':    
    app.run(host = "0.0.0.0", debug = True)