Commit ebcc4d62 authored by Axel Dürkop's avatar Axel Dürkop
Browse files

Ergänzungen

parent f962c2b3
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Das Request-Objekt in Flask\n",
"\n",
"Das folgende Skript simuliert ein Request-Objekt in Flask nach dem Versand eines HTML-Formulars. Dabei ist das Ziel, die Daten aus dem Formular in irgendeiner Form weiter zu verarbeiten."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Die Eigenschaft `request.form` ist nach dem Versand eines Formular ein `ImmutableMultiDict`. Das ist ein besonderer Datentyp in Flask, der auf einer Klasse aus [werkzeug](http://werkzeug.pocoo.org/docs/0.12/) basiert.\n",
"\n",
"Daher weisen wir zunächst einer Variablen ein so genanntes [MultiDict](http://werkzeug.pocoo.org/docs/0.12/datastructures/#werkzeug.datastructures.MultiDict) zu, das im Kontext von Flask ein komplexer Datentyp ist. Er hat die Form einer [Liste](https://docs.python.org/2/tutorial/introduction.html#lists) von [Tupeln](https://docs.python.org/2/tutorial/datastructures.html#tuples-and-sequences)."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"from werkzeug.datastructures import MultiDict\n",
"form_data = MultiDict([('tier', 'Hund'), ('beine', 4), ('alter', 7)])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Nun greifen wir zum Warmwerden auf die Werte dieser Variablen zu."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hund\n"
]
}
],
"source": [
"print(form_data['tier'])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
......@@ -12,22 +12,9 @@
},
{
"cell_type": "code",
"execution_count": 52,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<a data-flickr-embed=\"true\" data-footer=\"true\" href=\"https://www.flickr.com/photos/chris_fynn/17306765722/in/photolist-snkGus-caHnR1-xu821-rpTLoy-aHVVCa-9HCtuM-5TBbf9-5pdsTN-6uFfXS-as8AVu-ryWb7m-8ENynw-fKgdBp-dcnUCL-969ph6-6jJQy5-ogzafq-6PdEtv-aeQtWj-9Kx2Kf-6CyvD1-8EKodZ-6Pk8DB-7szfrX-6CYNJz-cXoYkw-9X4va3-aeyj55-7WP55r-eQoRR5-dUwpRX-aeyqYh-govHd6-i4dLKh-aeyiMN-begQVa-b7HMoX-8vaDer-7wq3Ya-5ETLwq-5hscmj-aevBiP-8arifu-aevtUv-nBuFiJ-4frgBF-aeybvw-6jED5P-dzEHCi-aeyj9u\" title=\"Mysore - Fruit vendor\"><img src=\"https://c1.staticflickr.com/9/8803/17306765722_a2d0be2f9e_n.jpg\" width=\"320\" height=\"213\" alt=\"Mysore - Fruit vendor\"></a><script async src=\"//embedr.flickr.com/assets/client-code.js\" charset=\"utf-8\"></script>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"%%HTML\n",
"<a data-flickr-embed=\"true\" data-footer=\"true\" href=\"https://www.flickr.com/photos/chris_fynn/17306765722/in/photolist-snkGus-caHnR1-xu821-rpTLoy-aHVVCa-9HCtuM-5TBbf9-5pdsTN-6uFfXS-as8AVu-ryWb7m-8ENynw-fKgdBp-dcnUCL-969ph6-6jJQy5-ogzafq-6PdEtv-aeQtWj-9Kx2Kf-6CyvD1-8EKodZ-6Pk8DB-7szfrX-6CYNJz-cXoYkw-9X4va3-aeyj55-7WP55r-eQoRR5-dUwpRX-aeyqYh-govHd6-i4dLKh-aeyiMN-begQVa-b7HMoX-8vaDer-7wq3Ya-5ETLwq-5hscmj-aevBiP-8arifu-aevtUv-nBuFiJ-4frgBF-aeybvw-6jED5P-dzEHCi-aeyj9u\" title=\"Mysore - Fruit vendor\"><img src=\"https://c1.staticflickr.com/9/8803/17306765722_a2d0be2f9e_n.jpg\" width=\"320\" height=\"213\" alt=\"Mysore - Fruit vendor\"></a><script async src=\"//embedr.flickr.com/assets/client-code.js\" charset=\"utf-8\"></script>"
......@@ -42,17 +29,9 @@
},
{
"cell_type": "code",
"execution_count": 53,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hallo Welt!\n"
]
}
],
"outputs": [],
"source": [
"print(\"Hallo Welt!\")"
]
......@@ -75,7 +54,7 @@
},
{
"cell_type": "code",
"execution_count": 54,
"execution_count": 1,
"metadata": {},
"outputs": [
{
......@@ -116,7 +95,7 @@
},
{
"cell_type": "code",
"execution_count": 55,
"execution_count": 2,
"metadata": {},
"outputs": [
{
......@@ -132,26 +111,35 @@
"print(sinn_des_lebens)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Hier haben wir eine Fließkommazahl gespeichert und ausgegeben. Auch sie gehört zu den **Numbers**."
]
},
{
"cell_type": "code",
"execution_count": 56,
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.99\n"
"45\n"
]
}
],
"source": [
"print(42+3)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Hier haben wir eine Fließkommazahl gespeichert und ausgegeben. Auch sie gehört zu den **Numbers**."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"preis = 1.99\n",
"print(preis)"
......@@ -173,17 +161,9 @@
},
{
"cell_type": "code",
"execution_count": 57,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Giraffe\n"
]
}
],
"outputs": [],
"source": [
"tier = \"Giraffe\"\n",
"print(tier)"
......@@ -205,17 +185,9 @@
},
{
"cell_type": "code",
"execution_count": 58,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['Giraffe', 'Salamander', 'Iltis']\n"
]
}
],
"outputs": [],
"source": [
"tiere = [\"Giraffe\", \"Salamander\", \"Iltis\"]\n",
"print(tiere)"
......@@ -237,17 +209,9 @@
},
{
"cell_type": "code",
"execution_count": 59,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'name': 'Dieter', 'gewicht': 5800, 'alter': 12}\n"
]
}
],
"outputs": [],
"source": [
"elefant = {\n",
" \"name\": \"Dieter\",\n",
......@@ -274,17 +238,9 @@
},
{
"cell_type": "code",
"execution_count": 60,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n"
]
}
],
"outputs": [],
"source": [
"schalter_1 = False\n",
"schalter_2 = True\n",
......@@ -309,22 +265,9 @@
},
{
"cell_type": "code",
"execution_count": 61,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/Z-folPNH6ro?list=PLD20BEE125C1FC7B1\" frameborder=\"0\" allowfullscreen></iframe>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"%%HTML\n",
"<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/Z-folPNH6ro?list=PLD20BEE125C1FC7B1\" frameborder=\"0\" allowfullscreen></iframe>"
......@@ -343,7 +286,7 @@
},
{
"cell_type": "code",
"execution_count": 62,
"execution_count": null,
"metadata": {
"collapsed": true
},
......@@ -371,17 +314,9 @@
},
{
"cell_type": "code",
"execution_count": 63,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Die Kartoffeln reichen nicht. Leider.\n"
]
}
],
"outputs": [],
"source": [
"kartoffeln = 3\n",
"\n",
......@@ -400,17 +335,9 @@
},
{
"cell_type": "code",
"execution_count": 64,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Das gibt genau einen Kartoffelpuffer.\n"
]
}
],
"outputs": [],
"source": [
"kartoffeln = 3\n",
"\n",
......@@ -458,19 +385,9 @@
},
{
"cell_type": "code",
"execution_count": 65,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hund\n",
"Katze\n",
"Maus\n"
]
}
],
"outputs": [],
"source": [
"tiere = ['Hund', 'Katze', 'Maus']\n",
"\n",
......@@ -507,17 +424,9 @@
},
{
"cell_type": "code",
"execution_count": 66,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Es ist Nachmittag.\n"
]
}
],
"outputs": [],
"source": [
"import time\n",
"\n",
......@@ -584,17 +493,9 @@
},
{
"cell_type": "code",
"execution_count": 67,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"8\n"
]
}
],
"outputs": [],
"source": [
"def verdoppeln(zahl):\n",
" print(zahl * 2)\n",
......@@ -622,8 +523,10 @@
},
{
"cell_type": "code",
"execution_count": 68,
"metadata": {},
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def verdoppeln(zahl):\n",
......
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