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

Update Notebooks

parent 44342788
......@@ -20,11 +20,13 @@
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"execution_count": 19,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Import des komplexen Datentyps, der für das Request-Objekt verwendet wird.\n",
"# Import des komplexen Datentyps MultiDict, der für das Request-Objekt verwendet wird.\n",
"from werkzeug.datastructures import MultiDict\n",
"\n",
"class Request():\n",
......@@ -33,8 +35,114 @@
" \n",
"# Wird von Flask intern erzeugt und verwaltet. Hier nur instanziiert,\n",
"# um die Schreibweise in einem Flask-View zu imitieren.\n",
"request = Request()\n",
"request = Request()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Das HTML-Formular\n",
"\n",
"Das Markup für ein einfaches Formular könnte nun wie folgt aussehen:"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"f = \"\"\"\n",
"<form action=\"/\" method=\"post\">\n",
" <p>\n",
" <label for=\"tier\">Tierart:</label>\n",
" <input type=\"text\" name=\"tier\" id=\"tier\" value=\"Hund\">\n",
" </p>\n",
" <p>\n",
" <label for=\"beine\">Anzahl der Beine:</label>\n",
" <input type=\"text\" name=\"beine\" id=\"beine\" value=\"4\">\n",
" </p>\n",
" <p>\n",
" <label for=\"alter\">Alter des Tiers:</label>\n",
" <input type=\"text\" name=\"alter\" id=\"alter\" value=\"7\">\n",
" </p>\n",
"</form>\n",
"\"\"\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Damit es hier gerendert gezeigt werden kann, brauchen wir einen Helfer:"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"<form action=\"/\" method=\"post\">\n",
" <p>\n",
" <label for=\"tier\">Tierart:</label>\n",
" <input type=\"text\" name=\"tier\" id=\"tier\" value=\"Hund\">\n",
" </p>\n",
" <p>\n",
" <label for=\"beine\">Anzahl der Beine:</label>\n",
" <input type=\"text\" name=\"beine\" id=\"beine\" value=\"4\">\n",
" </p>\n",
" <p>\n",
" <label for=\"alter\">Alter des Tiers:</label>\n",
" <input type=\"text\" name=\"alter\" id=\"alter\" value=\"7\">\n",
" </p>\n",
"</form>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from IPython.display import HTML\n",
"\n",
"h = HTML(f); h"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Voilà! Der Absendebutton fehlt, weil er in diesem Kontext nicht funktionieren würde."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Imitation der Formulardaten in Flask\n",
"\n",
"Senden wir dieses Formular ausgefüllt an den Server, hätten wir ein Request-Objekt in Flask zur Verfügung, das folgende Gestalt hat:"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Imitation eines Request-Objekts, wie es in Flask nach dem Formularversand vorhanden ist.\n",
"request.form = MultiDict([('tier', 'Hund'), ('beine', 4), ('alter', 7)])"
]
......@@ -43,12 +151,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Zugreifen auf die Request-Daten\n",
"\n",
"Nun greifen wir zum Warmwerden auf die Werte dieser Variablen zu."
]
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 23,
"metadata": {},
"outputs": [
{
......@@ -72,7 +182,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 24,
"metadata": {},
"outputs": [
{
......@@ -86,15 +196,6 @@
"source": [
"print(\"Das Tier ist {} Jahre alt.\".format(request.form['alter']))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
......
......@@ -12,9 +12,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"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"
}
],
"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>"
......@@ -29,9 +42,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hallo Welt!\n"
]
}
],
"source": [
"print(\"Hallo Welt!\")"
]
......@@ -54,7 +75,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 4,
"metadata": {},
"outputs": [
{
......@@ -95,7 +116,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 5,
"metadata": {},
"outputs": [
{
......@@ -113,7 +134,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 6,
"metadata": {},
"outputs": [
{
......@@ -137,9 +158,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.99\n"
]
}
],
"source": [
"preis = 1.99\n",
"print(preis)"
......@@ -161,9 +190,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Giraffe\n"
]
}
],
"source": [
"tier = \"Giraffe\"\n",
"print(tier)"
......@@ -185,9 +222,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['Giraffe', 'Salamander', 'Iltis']\n"
]
}
],
"source": [
"tiere = [\"Giraffe\", \"Salamander\", \"Iltis\"]\n",
"print(tiere)"
......@@ -209,9 +254,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'gewicht': 5800, 'name': 'Dieter', 'alter': 12}\n"
]
}
],
"source": [
"elefant = {\n",
" \"name\": \"Dieter\",\n",
......@@ -238,9 +291,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n"
]
}
],
"source": [
"schalter_1 = False\n",
"schalter_2 = True\n",
......@@ -265,9 +326,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"metadata": {},
"outputs": [],
"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"
}
],
"source": [
"%%HTML\n",
"<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/Z-folPNH6ro?list=PLD20BEE125C1FC7B1\" frameborder=\"0\" allowfullscreen></iframe>"
......@@ -286,7 +360,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"metadata": {
"collapsed": true
},
......@@ -314,9 +388,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Die Kartoffeln reichen nicht. Leider.\n"
]
}
],
"source": [
"kartoffeln = 3\n",
"\n",
......@@ -335,9 +417,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Das gibt genau einen Kartoffelpuffer.\n"
]
}
],
"source": [
"kartoffeln = 3\n",
"\n",
......@@ -385,9 +475,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 16,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hund\n",
"Katze\n",
"Maus\n"
]
}
],
"source": [
"tiere = ['Hund', 'Katze', 'Maus']\n",
"\n",
......@@ -424,9 +524,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 17,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Es ist Vormittag.\n"
]
}
],
"source": [
"import time\n",
"\n",
......@@ -493,9 +601,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 18,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"8\n"
]
}
],
"source": [
"def verdoppeln(zahl):\n",
" print(zahl * 2)\n",
......@@ -523,7 +639,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 19,
"metadata": {
"collapsed": true
},
......
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