Commit 24375120 authored by Duscha's avatar Duscha

Es wird keine Variable, sondern die User der Datenbank ausgegeben. Es gibt nur...

Es wird keine Variable, sondern die User der Datenbank ausgegeben. Es gibt nur eine funktionierende Seite, auf der die User aufgelistet werden.
parent 512eaf87
import sqlite3
from flask import Flask, render_template
myapp = Flask(__name__)
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
@myapp.route("/users")
def templ_test():
return render_template('users.html', string_aus = 'Whup whup!', list=[0,1,2,3,4,5])
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)
if __name__ == '__main__':
#print(dic)
#ausgabe()
#print(attribute())
myapp.run(host = "0.0.0.0", debug = True)
\ No newline at end of file
......@@ -6,20 +6,22 @@ connection = sqlite3.connect("test.db")
cursor = connection.cursor()
#Ab hier: ABSTRAKTION
#sql_command = """
#CREATE TABLE benutzer (
#b_nr INTEGER PRIMARY KEY,
#vname VARCHAR(40),
#nname VARCHAR(40),
#username VARCHAR(40),
#aktiv INTEGER,
#mail VARCHAR(60),
#beitritt DATE
#); """
#cursor.execute(sql_command)
cursor.execute("DROP TABLE IF EXISTS benutzer;")
sql_command = """
CREATE TABLE benutzer (
b_nr INTEGER PRIMARY KEY,
vname VARCHAR(40),
nname VARCHAR(40),
username VARCHAR(40),
aktiv INTEGER,
mail VARCHAR(60),
beitritt DATE
); """
cursor.execute(sql_command)
#Benutzer aus YAML-Datei lesen und in die Tabelle einfügen
with open('users.yaml') as f:
global users
users = yaml.safe_load(f)
#print(users)
......@@ -29,6 +31,8 @@ def addPerson(vname, nname, username, aktiv, mail, beitritt):
for x in range (0, 3):
addPerson(users[x] ['vname'], users[x] ['nname'], users[x] ['username'], users[x] ['aktiv'], users[x] ['mail'], users[x] ['beitritt'])
connection.commit()
connection.close()
#sql_command = """
#SELECT *
......
-
user id: 0
b_nr: 0
vname: Miriam
nname: Duscha
username: mduscha
......@@ -7,7 +7,7 @@
mail: mduscha@mail.de
beitritt: 2020-07-20
-
user id: 1
b_nr: 1
vname: Fabian
nname: Wandt
username: fwandt
......@@ -15,7 +15,7 @@
mail: fwandt@mail.de
beitritt: 2020-07-20
-
user id: 2
b_nr: 2
vname: Maria
nname: Dalton-Beatle
username: mariadb
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Meine Seite</title>
</head>
<body>
<br>
Dictionairy:
<ul>
{% for key,value in mydict.items() %}
<li> {{ key }} --&gt; {{ value }} </li>
{% endfor %}
</ul>
<br>
User:
<br>
<ul>
{% for user in user_list %}
<li> <a href="http://0.0.0.0:5000/users/{{user}}"> {{user}} </a> </li>
{% endfor %}
</ul>
<br>
Test:
<br>
{{userarray}}
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment