Added html template

This commit is contained in:
root 2023-06-02 10:11:06 +02:00
parent 44555aaa35
commit 9406e1fc50
2 changed files with 24 additions and 9 deletions

15
game.py
View File

@ -1,7 +1,7 @@
#! /bin/python3 #! /bin/python3
from random import choice from random import choice
from flask import Flask from flask import Flask, render_template
app = Flask(__name__, app = Flask(__name__,
static_url_path='', static_url_path='',
static_folder='static', static_folder='static',
@ -12,19 +12,16 @@ def hello():
title = 'A oder B' title = 'A oder B'
separator = ' oder ' separator = ' oder '
header = '<html><head><title>'+str(title)+'</title></head><link rel="stylesheet" type="text/css" href="/css/ab.css" /><body><div id="content"><div id="header">'+str(title)+'</div>' ablines = []
footer = "</div></body></html>"
ablines = ""
lines = getContent() lines = getContent()
for line in lines: for line in lines:
ab = line.split(separator) ab = line.split(separator)
ablines = '<div class="ab"><div class="a">'+str(ab[0])+'</div><div class="separator">'+str(separator)+'</div><div class="b">'+str(ab[1])+'</div></div>'+ablines ablines.append(
{'A': str(ab[0]), 'B': str(ab[1])}
)
output = header+ablines+footer return render_template('index.html', title=title, separator=separator, content=ablines)
return output
def getContent(): def getContent():
lines = [a.strip() for a in open("ab.txt").readlines()] lines = [a.strip() for a in open("ab.txt").readlines()]

18
templates/index.html Normal file
View File

@ -0,0 +1,18 @@
<html>
<head>
<title>{{ title }}</title>
<link rel="stylesheet" type="text/css" href="/css/ab.css" />
</head>
<body>
<div id="content">
<div id="header">{{ title }}</div>
{% for question in content %}
<div class="ab">
<div class="a">{{ question['A'] }}</div>
<div class="separator">{{ separator }}</div>
<div class="b">{{ question['B'] }}</div>
</div>
{% endfor %}
</div>
</body>
</html>