Skip to Content
Flask Framework Cookbook - Second Edition
book

Flask Framework Cookbook - Second Edition

by Shalabh Aggarwal
July 2019
Beginner to intermediate
302 pages
9h 38m
English
Packt Publishing
Content preview from Flask Framework Cookbook - Second Edition

There's more...

Now, many of us may be considering whether it would be possible to just declare GET and POST methods inside a View class and let Flask handle the rest of the stuff. The answer to this question is MethodView. Let's write our previous snippet using MethodView:

from flask.views import MethodView class GetPostRequest(MethodView): 
 
    def get(self): 
        bar = request.args.get('foo', 'bar') 
        return 'A simple Flask request where foo is %s' % bar 
 
    def post(self): 
        bar = request.form.get('foo', 'bar') 
        return 'A simple Flask request where foo is %s' % bar 
 
app.add_url_rule( 
    '/a-request', 
    view_func=GetPostRequest.as_view('a_request') 
) 
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

Writing a Web Application with Flask

Writing a Web Application with Flask

Doug Farrell
Mastering Flask

Mastering Flask

Jack Stouffer

Publisher Resources

ISBN: 9781789951295Supplemental Content