This is the course content for Websites with Python Flask, which has been developed and maintained by OpenTechSchool.
Hi, welcome to Websites with Python Flask. In this workshop we will take you through the fundamentals of creating dynamic websites using the Python Flask library. After the workshop you should have a rough mental picture of how websites work and some good pointers for getting further with websites of your own.
We only expect you to know a little Python, like from our Introduction to Programming workshop. You definitely do not need to know a lot. It will be best if you have a recent version of Python installed as well (version 3.3+).
Don’t worry if you know only a little HTML or none at all. We’ll be looking at how it all works rather than how to make it look pretty. HTML is important, but it’s only one part of making a website.
What we’ll do today
So we have this awesome idea for a website, Cats Everywhere, which lets people share pictures of cats via the internet. It’s innovative, it’s new, it’s exciting
But we don’t have any code yet.
Instead we’ll make a landing page, letting the internet know that a new era of cat pictures will soon begin. People can submit their email address to learn more when the real site goes live. By storing those addresses we’ll have a ready-made audience when the time comes to announce the real thing.
We’ll be using Python Flask as the web server. Cat lovers will be able to point their web browsers at our site, enter their email address, and hold their breath for the exciting launch!
We’ve put the final product online so you can see what we are aiming to do today. Here is the home page where people can enter their email address and the emails page where you can view the list of submitted emails.
A bit of history
Websites as we know them today started in 1991 from the work of Tim Berners-Lee at CERN. Most websites were static content; simple HTML pages stored on disk and sent directly to the browser. If people wanted to interact with others then they would have to do it by other means, such as email or USENET.
Since 1996 the most common web server has been ‘Apache HTTPD’, but from the late 1990s it was possible to build dynamic websites using a number of other language-specific platforms. Popular choices were Servlets (Java), Perl, PHP, Zope (Python) and ASP (Microsoft IIS).
Web servers eventually enabled programmers to write dynamic interactive websites in a variety of languages such as Perl, PHP, Ruby and Python. To enable this, web servers provide an interface to those programming languages so they can communicate. The first common one was called CGI (Common Gateway Interface), but modern ones now include FCGI, Rack, and WSGI (which python uses).
When the web became ubiquitous in the early 2000s many programmers were fed up with the work required to build and maintain large websites. From previous experience new platforms were built. Of these the most popular by far are Ruby on Rails and Python Django. These very large frameworks controlled the vast majority of the developer experience. Once set up they can make complicated websites very quickly, but can also require a lot of experience to master. A high learning curve, but with big payoffs.
Many developers do not require such large and complicated tools, and so microframeworks are also common today for building simple web functionality. As well as Flask, which we’ll be using today, there are other popular microframeworks. These include:
- Sinatra (which uses the programming language Ruby).
- Bottle (which uses Python).
These are all small focused libraries that provide just the bare essentials, but can usually be extended into more complicated solutions.
We’ll be using Flask to get you jump-started in developing dynamic websites!
Core workshop material
- Setting up - Installation instructions for Windows, OSX and Linux.
- Hello, World! - Serving our first web page.
- Files & Templates - How to show pictures of cats, and a prettier version of our home page.
- Forms - How forms work on the web.
- Form Submission - Receiving and processing the form.
- Data Structures - Storing our emails and displaying dynamic lists in web pages.
Extra fun stuff
Of course the core workshop can’t cover everything. But we’ve prepared these extra topics to guide you with things you might be interested in. You can pick-and-choose whichever ones you want, they are all independent of each other.
- Learning HTML and CSS - More on creating web pages.
- Professional CSS - How the pros style their websites.
- Keeping track of users - Using sessions to persist data over multiple visits.
- Using Databases - How to store data permanently.
- Hosting on Heroku - Host your website for free online using Heroku.