Exercise 8: A First Flask Application

In this lab we will start building up the tools that will be required for building the backend of web applications. The backend needs to be able to respond to web requests, store data and dynamically build web pages and data structures. As such, there are a number of key technologies you will need to be familiar with.

First things first....

By now you should have formed a project group, and begun discussing your ideas for the project. You should be able to register your project using this application. It is a small Flask application to record your project groups, the title of your project, and allow you to book the time you would like to demonstrate your project in week 12.

Once you have registered your group, discuss your idea with the lab demonstrator. Try and identify the user stories involved with the project, some sample polls/ranking it may show, and sketch some interface designs.

The application is running on the development flask server, and using SQLite as a database, so is not ready for full deployment, but it serves as a basic template for the sort of things you will require in your project. You can find the source code for the project on GitHub. This includes the basic instructions for running the application via the README.md file. You can download a copy of the application from Github to run yourself. However, complete the First Flask App exercise below first. Please send any questions, comments or bugs on the app to Tim.

First Flask App

Miguel Grinberg has produced an excellent set of tutorials for building Flask apps. Work through the first three chapters of their mega tutorial. It is very important to get your python and Flask environment set up correctly. The instructions in the mega tutorial are very good, but ask for help if you don't understand anything, as this development environment will be very important for the rest of semester.

Lauren Gee has prepared some detailed notes on setting up a flask project within VSCode.

Running Static HTML Files

If you would like to run your web pages from early labs on your flask server, you can create a folder called static in the app directory and place the files there. When you navigate to localhost flask will look in the static directory for resources, so you can put the webpage name at the end of the local host url. You can then see your requests being sent to the flask web-server.

For example, if you have a static HTML file called calculator.html, and you've placed it under app/static/calculator.html, you should be able to access it via http://localhost:5000/static/calculator.html