To learn more about concepts covered in this lesson, you can check out:
Deploying the Application to Heroku
00:00 Deploying the Application to Heroku. Heroku makes building and deploying applications really friendly for developers. It removes much of the burden related to building and running web applications, taking care of most infrastructure details and letting you focus on creating and improving the app.
00:21 Some of the details handled by Heroku include provisioning HTTPS certificates, managing DNS records, and running and maintaining servers. In this part of the course, you’ll learn how to deploy the previously created web application to the internet using Heroku. By the end of this section, your app will be publicly available under a nice URL and served using HTTPS.
00:46 Your first step is to create a Heroku account. If you don’t have one already, you can use the Free and Hobby Plan. It allows you to deploy non-commercial applications, personal projects, and experiments without spending money.
01:13 The Heroku command-line interface, CLI, is a tool that allows you to create and manage Heroku applications from the terminal. It’s the quickest and the most convenient way to deploy your application.
01:38 Once you have the Heroku CLI installed, you’ll need to log in. You can do this by running the following command from a terminal. This opens a website with a button to complete the login process.
Now you’ll learn how to use the Heroku CLI and Git to deploy your web application. The first step is to create a file named
Procfile in that project’s root directory. This file tells Heroku how to run the app.
02:27 Note that this filename must start with a capital letter, and the file cannot contain any comments. This file tells Heroku to serve your application using Gunicorn, a Python Web Server Gateway Interface (WSGI) HTTP server compatible with various web frameworks, including Flask.
As files have been added and changed, they’ll need to be committed to Git. This can be done using the commands seen on-screen. Firstly, the latest versions of
requirements.txt are added to the Git repository, and then a commit with an appropriate name is created.
You’re now ready to deploy the application to Heroku. You’ll start by creating a Heroku application using the Heroku CLI. Note that this course uses
realpython-flask-app as the application name. This command initializes the Heroku application, creating a git remote named
03:48 Since application names need to be unique on Heroku, you’ll need to choose a different name for your deployment. Next, you can push the Git repository to this remote to trigger the build and deployment process.
04:02 After pushing the master branch to the Heroku remote, you’ll see that the output displays information about the building and deployment process. The output indicates that Python 3.9 will be used at your application’s runtime.
Congratulations, the app is now online. The output shows the build process, including the installation of dependencies in the deployment. Towards the bottom, you’ll find the URL for your application. In this case, it’s
realpython-flask-app.herokuapp.com, as seen on-screen. The app name is before
herokuapp, so now you can see why the app name needs to be unique.
"Hello World!" is replaced by
"Hello this is the new version!". This new version can be deployed on Heroku by committing and pushing the changes to the Heroku remote. Firstly, the app file is added.
06:01 This triggers the build and deployment process again. You can repeat these steps whenever you need to deploy a new version of your application. You’ll notice that subsequent deployments usually take less time because the requirements are already installed.
06:22 For more details about how to use the Heroku CLI to deploy Python applications, follow the link on-screen to the Heroku documentation. In the next section of the course, you’ll see how to use Heroku pipelines to aid your development workflow.
Become a Member to join the conversation.