Building Web Applications With Flask - Sample Chapter
Building Web Applications With Flask - Sample Chapter
$ 34.99 US
22.99 UK
P U B L I S H I N G
E x p e r i e n c e
D i s t i l l e d
Sa
m
pl
C o m m u n i t y
Italo Maia
ee
Italo Maia
for the mobile, Web, and desktop environments, having dedicated most of the last
few years to development with Python and web technologies.
Author of Flask-Empty, a popular skeleton for Flask projects that aggregates
good practices and recipes for quick prototyping, he is active in the Brazilian
Python communities, having open source tools and libraries available in GitHub
and Bitbucket.
Preface
One can hardly develop new applications in our "now world" without duct-taping
a lot of technologies together, be it new trend databases, messaging systems, or
languages of all kinds. When talking about web development, things might get
slightly more complicated as not only do you have to mix a lot of technologies
together, but they must also work well with the applications accessing them (also
known as web browsers). They should also be compatible with your deployment
server, which is another story in itself!
In the Python world, where people deliver amazing desktop software following
great guidelines such as the Zen of Python and PEP8, we have, at our disposal, a
wide range of libraries and frameworks for creating great web applications, each
with its own philosophy. Django, for example, is a bundle solution; it makes choices
for you on how your project should look, what should it have, and how things
should be done. Web2py is another framework solution that goes beyond and
bundles even the IDE with it. These are great concepts, but if you want to create
something simple, I would suggest you to do it somewhere else. They're usually
good choices, but sometimes they're just too much (the latest Django version seems
decisive in changing that; let's keep an eye on further developments).
Flask positions itself, not as a full-power out-of-the-box solution like both Django
and Web2py, but as a minimalistic solution where you're given the bare minimum to
work with and choose all the other stuff. That's very helpful when you want granular
control of your application, when you want to precisely pick your components, or
when your solution is simple (not simplistic, okay?).
Preface
This book is a response to that scenario of beautiful code and many options in the
Web world. It tries to walk through the main concerns regarding web development,
from security to content delivery and from session management to REST services
and CRUD. Important modern concepts such as overengineering, quality and the
development process are covered, so as to achieve better results from day one. To
make the learning process smooth, subjects are presented without rush and followed
by commented examples. The book also sets out to give readers real-world advice on
how to prevent common problems with code.
Come learn how to create great Flask applications, delivering value to your projects
and customers!
Preface
Chapter 9, Extensions, How I Love Thee, covers all those great Flask extensions not
covered so far that will help you achieve the productivity the real world requires
from you.
Chapter 10, What Now?, ends our development trip covering all the basics for a
healthy deployment, and points you toward your next steps in the Flask world.
Flask in a Flask,
I Mean, Book
What is Flask? It's a question that humanity has been pondering for millennia... well,
actually, since 2010, when Armin Ronacher first committed to the project. Flask is a
Web framework and is quite different from what most people are used to working
with. It is less presumptuous about how your application should look or what you
should use to make it available. The BSD licensed package has all this!
Request dispatching
Secure cookies
Sessions
With that much, you can handle Ajax requests, browser requests, and user sessions
between requests; route HTTP requests to your controllers; evaluate form data;
respond to HTML and JSON; and so on.
That is nice, but is Flask not an MVC framework? Well, that's arguable. If a web
framework does not implement an MVC antipattern, such as handling requests
in the view or mixing models and controllers, it could potentially facilitate an
MVC, which, in my opinion, is as good as it gets because it does not enforce your
application structure.
Flask is not an MVC framework as it does not implement the
model layer, although it does not restrict you in any way if you
wish to create your own.
If you need a simple, single-file web application that receives a form and gives
back an answer, HTML or not, Flask will help you with that, easily. If you need a
multilayer, high-depth modularized Facebook clone, Flask can also be there for you.
So, what did we learn so far?
Right now, you might be wondering which of your neat project ideas could be done
with Flask. That's the spirit! What about thinking together on this one?
Flask does not come with bundled functionality in terms of database integration, a
forms library, administration interface, or migration tools. You can have these through
extensions, which will be discussed soon enough, but they are all external to Flask. If
you need these extensions right at the beginning of your project and you don't want to
set it up (or can't spare the time to), you might do better with a full-fledged MVC all-in
one, low-cohesive, and high-coupling framework such as Django.
[2]
Chapter 1
Now, imagine you need to build a website with a single form, such as a
http://cashcash.cc/ clone, which receives a form and returns the current
currency trade values; Flask could help conclude your project really fast.
Let's think further. What if you need a specific set of libraries to work together
in your project and you don't want the web framework getting in the way; that's
another very good scenario for Flask as it gives you the bare minimum and lets you
put together everything else you may need. Some frameworks have such a high
level of coupling (read dependency) on their own components that you may have a
serious problem if you want to use a specific alternative.
For example, you may want to use a NoSQL database in your project; however, if
you do so, some components of your project may stop working (for example: an
administrative component).
Basically, if you have the time to spare, if you're doing something simple, if you want
to implement your own architecture solution, or if you need granular control of the
components used in your project, Flask is the web framework for you.
Summary
Now, let's talk about awesomeness, your awesomeness after reading this bookyou
will be capable of handling HTTP and Ajax requests; creating fully featured web
applications with database integration (SQL and NoSQL) and REST services; using
Flask extensions (forms, caching, logging, debugging, auth, permissions, and so on);
and modularizing and unit- and feature-testing your applications.
I hope you enjoy this book and build great things with what you learn here
[3]
www.PacktPub.com
Stay Connected: