Skip to Content
Mastering Flask Web Development - Second Edition
book

Mastering Flask Web Development - Second Edition

by Daniel Gaspar, Jack Stouffer
October 2018
Intermediate to advanced
332 pages
8h 9m
English
Packt Publishing
Content preview from Mastering Flask Web Development - Second Edition

Put requests

As listed in the table at the beginning of this chapter, PUT requests are used to change the values of an existing resource. Like the post method, the first thing that we should do is create a new parser in parsers.py, as follows:

post_put_parser = reqparse.RequestParser()post_put_parser.add_argument(    'title',    type=str,    location=('json', 'values'))post_put_parser.add_argument(    'text',    type=str,    location=('json', 'values'))post_put_parser.add_argument(    'tags',    type=str,    action='append',    location=('json', 'values'))

The logic for the put method is very similar to the post method. The main difference is that each change is optional and any request that does not provide post_id is denied, as shown in the following code:

...def 
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Flask Web Development, 2nd Edition

Flask Web Development, 2nd Edition

Miguel Grinberg
Flask Web Development

Flask Web Development

Miguel Grinberg

Publisher Resources

ISBN: 9781788995405Supplemental Content