Introduction to Tornado by Brendan Berg Allison Parrish Michael Dory

Introduction to Tornado by Brendan Berg Allison Parrish Michael Dory

Author:Brendan Berg, Allison Parrish, Michael Dory [Brendan Berg, Allison Parrish, Michael Dory]
Language: eng
Format: epub
Publisher: O'Reilly Media, Inc.
Published: 2018-10-03T00:00:00+00:00


{% extends "main.html" %} {% autoescape None %} {% block body %} <form method="POST"> ISBN <input type="text" name="isbn" value="{{ book.get('isbn', '') }}"><br> Title <input type="text" name="title" value="{{ book.get('title', '') }}"><br> Subtitle <input type="text" name="subtitle" value="{{ book.get('subtitle', '') }}"><br> Image <input type="text" name="image" value="{{ book.get('image', '') }}"><br> Author <input type="text" name="author" value="{{ book.get('author', '') }}"><br> Date released <input type="text" name="date_released" value="{{ book.get('date_released', '') }}"><br> Description<br> <textarea name="description" rows="5" cols="40">{% raw book.get('description', '')%}</textarea><br> <input type="submit" value="Save"> </form> {% end %}

This is a fairly conventional HTML form. We’re using the book dictionary passed in from the request handler to prepopulate the form with data from the existing book, if any; we use the Python dictionary object’s get method to supply a default value for a key if the key isn’t present in the dictionary. Note that the name attributes of the input tags are set to the corresponding key of the book dictionary; this will make it easy to associate the data from the form with the data we want to put into the database.

Also note that, because the form tag lacks an action attribute, the form’s POST will be directed to the current URL, which is precisely what we want (e.g., if the page was loaded as /edit/0-123-456, the POST request will go to /edit/0-123-456; if the page was loaded as /add, the POST will go to /add). Figure 4-1 shows what the page looks like when rendered.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.