Commit 512eaf87 authored by Duscha's avatar Duscha

Grundgerüst: Jinja Seite mit statischer Variable (in Docker, mit Python)

parents
FROM python:3.7.3
RUN pip3 install Flask
RUN pip3 install jinja2
RUN pip3 install pyyaml
COPY . /website
CMD python3 sqlite1.py, python3 run.py
from flask import Flask, render_template
myapp = Flask(__name__)
@myapp.route("/users")
def templ_test():
return render_template('users.html', string_aus = 'Whup whup!', list=[0,1,2,3,4,5])
if __name__ == '__main__':
myapp.run(host = "0.0.0.0", debug = True)
\ No newline at end of file
#!/usr/bin/python3
import sqlite3
import yaml
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)
#Benutzer aus YAML-Datei lesen und in die Tabelle einfügen
with open('users.yaml') as f:
users = yaml.safe_load(f)
#print(users)
def addPerson(vname, nname, username, aktiv, mail, beitritt):
cursor.execute("INSERT INTO benutzer(vname, nname, username, aktiv, mail, beitritt) VALUES (:vn, :nn, :un, :akt, :mail, :bei)", {'vn': vname, 'nn': nname, 'un': username, 'akt': aktiv, 'mail': mail, 'bei': 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'])
#sql_command = """
#SELECT *
#FROM benutzer;
#"""
#cursor.execute(sql_command)
#print(cursor.fetchall())
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Meine Seite</title>
</head>
<body>
{{string_aus}}
</body>
</html>
\ No newline at end of file
File added
-
user id: 0
vname: Miriam
nname: Duscha
username: mduscha
aktiv: 1
mail: mduscha@mail.de
beitritt: 2020-07-20
-
user id: 1
vname: Fabian
nname: Wandt
username: fwandt
aktiv: 1
mail: fwandt@mail.de
beitritt: 2020-07-20
-
user id: 2
vname: Maria
nname: Dalton-Beatle
username: mariadb
aktiv: 0
mail: mariadb@mail.de
beitritt: 2017-04-20
\ 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