86 lines
No EOL
2.2 KiB
Python
86 lines
No EOL
2.2 KiB
Python
from flask import Flask
|
|
|
|
app = Flask(__name__)
|
|
|
|
@app.route("/")
|
|
def hello():
|
|
return "Willkommen in unserem Escape Room!"
|
|
|
|
if __name__ == "__main__":
|
|
app.run(host="0.0.0.0", port=9011) # 90 + Raumnummer
|
|
|
|
|
|
from flask import Flask, request
|
|
|
|
app = Flask(__name__)
|
|
|
|
@app.route("/")
|
|
def hello():
|
|
return "Hallo aus meiner Flask-App!"
|
|
|
|
@app.route("/frage", methods=["GET", "POST"])
|
|
def frage():
|
|
if request.method == "POST":
|
|
if request.form["antwort"] == "8":
|
|
return "Richtig!"
|
|
return "Leider falsch."
|
|
return '<form method="post">Was ist 3 + 5? ' \
|
|
'<input name="antwort"><button>OK</button></form>'
|
|
|
|
if __name__ == "__main__":
|
|
app.run(host="0.0.0.0", port=9011)
|
|
|
|
|
|
from flask import Flask, request, redirect
|
|
|
|
app = Flask(__name__)
|
|
eintraege = [] # speichert die Nachrichten (im Arbeitsspeicher)
|
|
|
|
@app.route("/pinnwand", methods=["GET", "POST"])
|
|
def pinnwand():
|
|
if request.method == "POST":
|
|
eintraege.append(request.form["nachricht"])
|
|
return redirect("/app/pinnwand")
|
|
liste = ""
|
|
for e in eintraege:
|
|
liste = liste + "<li>" + e + "</li>"
|
|
return '<h1>Pinnwand</h1>' \
|
|
'<form method="post"><input name="nachricht">' \
|
|
'<button>Senden</button></form><ul>' + liste + '</ul>'
|
|
|
|
if __name__ == "__main__":
|
|
app.run(host="0.0.0.0", port=9011)
|
|
|
|
|
|
from flask import Flask
|
|
import sqlite3
|
|
|
|
app = Flask(__name__)
|
|
|
|
def get_db():
|
|
db = sqlite3.connect("adventure.db")
|
|
db.row_factory = sqlite3.Row # Spalten per Name ansprechen
|
|
return db
|
|
|
|
@app.route("/")
|
|
def start():
|
|
return '<h1>Verlies</h1><a href="/app/raum/1">Abenteuer starten</a>'
|
|
|
|
@app.route("/raum/<int:id>")
|
|
def raum(id):
|
|
db = get_db()
|
|
r = db.execute("SELECT name, beschreibung FROM raeume WHERE id=?", (id,)).fetchone()
|
|
ausgaenge = db.execute(
|
|
"SELECT richtung, nach_raum FROM ausgaenge WHERE von_raum=?", (id,)
|
|
).fetchall()
|
|
db.close()
|
|
|
|
html = "<h1>" + r["name"] + "</h1>"
|
|
html = html + "<p>" + r["beschreibung"] + "</p>"
|
|
for a in ausgaenge:
|
|
html = html + '<a href="/app/raum/' + str(a["nach_raum"]) + '">' \
|
|
+ a["richtung"] + '</a> '
|
|
return html
|
|
|
|
if __name__ == "__main__":
|
|
app.run(host="0.0.0.0", port=9011) |