TLDR: Skip To The Bottom of This Post/Rant for the Answer to Handling HTTP POST & GET Requests in Python with Flask (the Easy Way)
Just sort of wanted to vent here for a minute… I’m working out of Miguel Grinberg’s Flask Web Development (2nd Edition) trying to teach myself Flask and I’m really frustrated: I’m only on Chapter 4 and this guy has already thrown in Bootstrap and another 3rd party library (Flask-WTF) and the examples are quickly growing in complexity to the point where I’m having trouble following along. I wish authors would just keep things as simple as possible. There’s no need to use every feature, and every library, when writing a programming book or tutorial. Programming is complicated enough.
O well I suppose. I got a lot out of the first three chapters, but it looks like I’m going to have to move on to another book to keep learning. Tossing in this Flask-WTF library and using the ‘extends’ and ‘block’ features in the Jinja2 templates just makes it too confusing as a complete beginner. I’m sure that the ‘extends’ and ‘block’ features are nice to have, but they aren’t appropriate this early in a programming tutorial. Just demonstrate how to do something in its most simplest form.
TAKEAWAY: Read all the programming books on a given subject. Take what you can from each book, and move on to the next when necessary.
UPDATE: Here are the three other books on Flask which I’m planning on diving into tonight–
- Building Web Applications with Flask by Italo Maia
- Flask by Example by Gareth Dwyer
- Learning Flask Framework by Matt Copperwaite & Charles Leifer
UPDATE: Okay, so two of the three new books also jump straight into handling HTTP GET & POST Requests using Flask-WTF, but luckily Flask By Example kept things simple and demonstrated the simplest way to handle networking requests. Need to grag some GET or POST data? Simply call:
# Retrieve Data from an HTTP GET Request from flask import request username = request.args.get("username")
# Retrieve Data from an HTTP POST Request # Additional Reference: https://bit.ly/2HsJtD1 # Note, we are using HTTP POST, However the # Method Name is Still .get() # A Bit confusing eh? from flask import request username = request.form.get("username") password = request.form.get("password")