diff options
| -rw-r--r-- | app.py | 43 | ||||
| -rw-r--r-- | templates/.index.html.swp | bin | 0 -> 12288 bytes | |||
| -rw-r--r-- | templates/index.html | 20 |
3 files changed, 63 insertions, 0 deletions
@@ -0,0 +1,43 @@ +from flask import ( + Flask, + render_template, + request +) +import pymongo + + +class dbProxy(object): + def __init__(self, mongouri): + self.client = pymongo.MongoClient(mongouri) + self.db = self.client['jokevotedb'] + + def getJokes(self): + jokes = [] + for joke in self.db.jokes.find(): + jokes.append(joke) + return jokes + + def addJoke(self, text): + self.db.jokes.insert_one({'text': text, 'votes': 0}) + + +app = Flask(__name__) +db = dbProxy( + 'mongodb://jokevote:jokevote@127.0.0.1:27017/jokevotedb') + + +@app.route('/') +def root(): + jokes = db.getJokes() + return render_template('index.html', jokes=jokes) + + +@app.route('/submit', methods=['POST']) +def submit(): + text = request.form['text'] + db.addJoke(text) # TODO secure this + return root() + + +if __name__ == '__main__': + app.run(debug=True) diff --git a/templates/.index.html.swp b/templates/.index.html.swp Binary files differnew file mode 100644 index 0000000..b9af402 --- /dev/null +++ b/templates/.index.html.swp diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..2122678 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,20 @@ +<!doctype html> +<html lang="de"> +<meta charset="utf-8"> +<head> + <title>Lehrerspruch-Wahlplattform</title> +</head> +<body> + <h1>Lehrersprüche</h1> + <ul> + {% for joke in jokes %} + <li>{{ joke.text }}</li> + {% endfor %} + </ul> + <form action="submit" method="post"> + Neuen Spruch hinzufügen + <input type="text" name="text"> + <input type="submit" value="hinzufügen"> + </form> +</body> +</html> |
