My Flask Web Development Book is Out!

Posted by
on under

It was a long wait, but my book is finally here! You can now buy Flask Web Development at most online bookstores, and if you are lucky you may also spot it at some brick and mortar retailers.

With the book out in the wild I thought an update is in order. In this post I will give you a summary of what I have done so far with regards to Flask training, and will conclude with the next projects that will be coming in the near future.

Free Flask Tutorials

As you probably know, I wrote the software that powers this blog in Flask, and based on that initial experience with the framework I went on to create many tutorials. In this section you can see an organized list of what's available and where.

The Flask Mega-Tutorial

The Flask Mega-Tutorial was my first tutorial, and is probably the best known. It is comprised of 18 parts, covering many different aspects of web application development with Python and Flask.

If you decide to do this tutorial you should keep in mind that it is about two years old, and it is starting to age a bit. The most important disadvantage is that these articles were written before Flask had support for Python 3, so the code examples need a few minor touches to run on the newer Python releases. The concepts are still valid and apply to Python 3, but the syntax is outdated.

Also important to note is that the organization of this tutorial is not as good as in my more recent efforts, as I started writing it without having designed the complete structure of the course. I basically wrote articles about topics that I was interested at the time. They say that the best way to learn something is to teach it to others, and that has been true for me. The early tutorials and all the questions I receive from readers allowed me to learn more and be able to present topics in a much more organized way in the material I created more recently.

Even with these minor issues people seem to like this tutorial a lot, so it is still a valid option to get a taste of what writing a real application with Flask involves.

Click here to go to the first Mega-Tutorial article

Writing REST APIs with Flask

In between mega-tutorial articles I wrote a shorter series that specifically addresses different aspects of writing RESTful APIs using Flask. This series even covers a bit of Javascript client side development, so it is definitely a great option if you are interested on rich clients and server-side APIs.

Click here to see my REST API articles

Python Web Development With Flask: an O'Reilly Webcast

To promote my book, O'Reilly asked me to do a one hour webcast presentation on a topic of my choice, and I decided to do a beginner's introduction to Flask. In this session you can see my screen as I explain and demonstrate five Flask applications. The code is available on GitHub for you to install and try on your own.

In the last 20 minutes of the presentation I answered questions from the attendees. There were some pretty interesting questions, covering topics such as the Raspberry Pi and comparisons with Node.js, Django and PHP.

Click here to view my O'Reilly webcast

Due to the success of this session I've been asked to present again later this year, on a date still to be determined. If you have any suggestions for topics you would like to hear me discuss let me know below in the comments!

PyCon Videos

I presented two sessions at PyCon 2014 in Montréal. The first is a three and a half hour long tutorial where I explain an entire application, step by step. This is a session directed at people with previous Python experience, but no Flask experience is required.

The second session is directed towards intermediate/advanced developers. In it I show some of the patterns and tricks I use to develop REST APIs with Flask. Some people dubbed this talk "Flask Decorators on Steroids". If you want to know why, you'll have to watch it.

The Book

If you are looking for the latest and greatest in my Flask training material then I hope you will consider my Flask Web Development book.

In this book you follow me through the development of a nicely featured social blogging application, from start to end. Unlike my Mega-Tutorial, the book covers the most recent version of Flask (0.10.1), which has full support for Python 3. I was careful to write the example code in a way that is compatible with Python 2 and Python 3, so indirectly you will also learn about good practices around development of Python code that works on both versions.

The book is available through most online retailers, and also directly from oreilly.com, in print or e-book formats. I have created http://flaskbook.com to provide information about the book. Click the cover below to visit this site:

I thought I'd mention that O'Reilly offers a print + e-book combo option that is great for those that want a paper book but also want to receive the free e-book updates that include corrections and improvements. Also note that unlike the big retailers (Amazon, B&N, etc.) when you buy the e-book from O'Reilly you get DRM-free files in several formats, so you can install copies of the book on your tablet, phone, computer, kindle, nook, etc. And you are also allowed to make personal backups.

OSCON

If you are coming to OSCON this year, then you'll have a chance to meet with me in person. I love this conference, not only because it is great, but also because it is located in my home town, a short 20 minute train ride away. I will be signing free copies of my book at the O'Reilly booth, and will be happy to meet with readers to answer questions or just chat.

The Future

O'Reilly is very pleased with my book, which has generated interest well above their expectations (and mine!). I'm also very happy to be part of the O'Reilly family, so it seemed natural to both that we should continue our association.

The question is what to do next.

I have found from reviews of my book that some people are very interested in learning Flask but don't have the baseline Python experience that is required to use the book. On the other side, I have also seen reviews that say that the book is too basic, that I should have included more advanced stuff.

In discussing this with my editor we have come up with the idea of producing a couple of video tutorials to complement the book. The details are still very sketchy, but I'm thinking one of the videos will start at a pretty basic level and will be centered around a smaller and simpler application. The other video tutorial will cover advanced topics, likely in the area of API development.

The nice thing about videos is that it takes a lot less time to produce than a book. The timelines we are discussing would put these videos out around August or September of this year. (Update: the two Flask training videos are out now, see http://flaskbook.com for more information!)

As always I love to hear your comments, so feel free to let me know your ideas, suggestions or anything else you want to say.

Thanks!

Miguel

Become a Patron!

Hello, and thank you for visiting my blog! If you enjoyed this article, please consider supporting my work on this blog on Patreon!

29 comments
  • #26 ella ramos said

    Hi Miguel,

    I have been reading your book. On page 105 (Account confirmation).
    This line of code confused me on the confirm() function.

    def confirm(self, token):
    s = Serializer(current_app.config['SECRET_KEY'])
    try:
    data = s.loads(token)
    except:
    return False
    if data.get('confirm') != self.id:
    return False
    self.confirmed = True
    db.session.add(self)
    return True

    What does db.session.add(self) do? Does it assigned the "True" value to confirmed Column?

    Thank you!
    Great book! I am learning a lot.

  • #27 Miguel Grinberg said

    @ella: the db.session.add() call adds the object passed as an argument to the current database session. Flask-SQLAlchemy is configured to commit the session at the end of the request, so this is basically saying that we want this object updated on on the database, after the confirmed attribute was set to True.

  • #28 Rodolfo Alvarez said

    Hi Miguel, I have learnt a lot using your book . Thanks. I started to develop a view function to upload a mailing list to email service provider, and without realising I was using an object 'user' to assign attributes like 'user.email = value' . When I was checking my code I realised that I was using the object 'user' (in a natural way) but I couldn't find out where it was created. I inserted a 'print(type(user))' in my code and it returns <class 'function'>. Where the object 'user' is created ? Is it part of one of the imported packages ? Here is the snippet: (it works but I have this doubt)

    @admin_required
    @main.route('/upload_old_mailing_list', methods=['POST','GET'])
    def upload_old_mailing_list():
    print('Type user {}'.format(type(user)))
    s = URLSafeSerializer(app.config['SECRET_KEY'], salt='unsubscribe')
    with open( 'old_mailing_list.csv', 'r', newline='') as ifile:
    reader = csv.DictReader(ifile)
    for row in reader:
    user.username = row['Name']
    user.email = row['E-mail 1 - Value']
    token = s.dumps(user.username + ' ' + user.email )
    add_list_member(user, token=token, old='old_mailing_list')
    ifile.close()
    return 'Successssss'

    Could you please tell me how or when 'user' is created or where I can read more about this ? Thank you very much .
    Rodolfo

  • #29 Miguel Grinberg said

    @Rodolfo: the "user" variable is actually not a variable, it is the user() function. In this case the scoping rules in Python allow you to use a local variable named user, while there is also a function in the global scope named user().

Leave a Comment