Commit 512eaf87 authored by Duscha's avatar Duscha

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

FROM python:3.7.3
RUN pip3 install Flask
RUN pip3 install jinja2
RUN pip3 install pyyaml
COPY . /website
CMD python3, python3
from flask import Flask, render_template
myapp = Flask(__name__)
def templ_test():
return render_template('users.html', string_aus = 'Whup whup!', list=[0,1,2,3,4,5])
if __name__ == '__main__': = "", debug = True)
\ No newline at end of file
import sqlite3
import yaml
connection = sqlite3.connect("test.db")
cursor = connection.cursor()
#sql_command = """
#CREATE TABLE benutzer (
#vname VARCHAR(40),
#nname VARCHAR(40),
#username VARCHAR(40),
#aktiv INTEGER,
#mail VARCHAR(60),
#beitritt DATE
#); """
#Benutzer aus YAML-Datei lesen und in die Tabelle einfügen
with open('users.yaml') as f:
users = yaml.safe_load(f)
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 = """
#FROM benutzer;
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<title>Meine Seite</title>
\ No newline at end of file
File added
user id: 0
vname: Miriam
nname: Duscha
username: mduscha
aktiv: 1
beitritt: 2020-07-20
user id: 1
vname: Fabian
nname: Wandt
username: fwandt
aktiv: 1
beitritt: 2020-07-20
user id: 2
vname: Maria
nname: Dalton-Beatle
username: mariadb
aktiv: 0
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