Building a Basic Python Web App
00:04 Google App Engine requires you to use a web framework for creating your web application in a Python 3 environment. Since you’re trying to use a minimal setup to get your local Python code up on the Internet, a microframework such as Flask is a good choice.
00:19 A minimal implementation of Flask is so small that you might not even notice that you’re using a web framework. The application you’re going to create will rely on several different files, so the first thing to do is to create a project folder to make sure everything is in the same place.
Create a project folder and give it a name that’s descriptive of your project. For this practice project, call the folder
hello-app. You’ll need three files inside this folder, as seen on-screen.
app.yaml helps Google App Engine decide which settings to use on its server. While three files might sound a lot, you’ll see that this project uses fewer than ten lines of code across all of them.
This function defines what should be executed if the defined URL endpoint is requested by a user. Its return value determines what a user will see when they load the page. Note that the naming of
index() is only a convention.
If a user types the base URL of your web app into their browser, then Flask will run
index() and the user will see the returned text. In this case, the text is just one sentence:
Congratulations, it's a web app! You can render more complex content, and you can also create more than one function so that users can visit different URL endpoints in your app to receive different responses. However, for this initial implementation, it’s fine to stick with a short and encouraging success message.
If your app has other dependencies, then you’ll need to add them to your
requirements.txt file as well. Google App Engine will use
requirements.txt to install the necessary Python dependencies for your project when setting it up on the server.
04:04 It’s worth checking that the Python 3 Runtime Environment you want to use is available on Google App Engine. At the time of creating this course, Python 3.10 was the latest release version of Python, but Python 3.9 was the latest version available on Google App Engine.
You can use Google App Engine’s
04:47 These nine lines of code complete the necessary setup for this app. Your project is now ready for deployment. However, it’s good practice to test your code before putting it into production so you can catch potential errors.
Become a Member to join the conversation.