Stay organized with collections Save and categorize content based on your preferences.
Note: If you are deploying a new Python web service to Google Cloud, we recommend getting started with Cloud Run.Write and locally test a web service that serves a static HTML file using Flask. Then, create the configuration files that you need for deploying the web service to App Engine.
In this step, you create and locally test a version of a web service that displays placeholder data. The goal here is to ensure that your basic web service is working before adding Datastore and Firebase authentication.
Before you beginIf you have not already created a Google Cloud project, create a Google Cloud project.
If you have not already, set up your local environment for Python 3 development by completing the following:
Download and install Python 3 for developing your web service and running the Google Cloud CLI.
Use your Google Cloud user credentials to authenticate with the Google Cloud CLI and enable local testing with Datastore:
gcloud auth application-default login
Tip: For more extensive testing, it is recommended that you set up a service account rather than using user-end credentials. For more information on service accounts and other types of authentication, see Authentication Overview.The project directory where you create your web service will have the following file structure:
building-an-app/
app.yaml
main.py
requirements.txt
static/
script.js
style.css
templates/
index.html
The following sections provide an example of how to set up the files in your project directory.
Write your web serviceThe initial iteration of your web service uses Flask to serve a Jinja-based HTML template.
To set up your web service:
Create your templates/index.html
file:
Add behaviors and styles with static/script.js
and static/style.css
files:
In your main.py
file, use Flask to render your HTML template with the placeholder data:
Configure all dependencies you will need for your web service in your requirements.txt
file:
Test your web service by running it locally in a virtual environment:
Mac OS / Linuxpython3 -m venv env
source env/bin/activate
hello_world
sample code. Then install dependencies:
cd YOUR_SAMPLE_CODE_DIR
pip install -r requirements.txt
python main.py
http://localhost:8080
Use PowerShell to run your Python packages.
python -m venv env
.\env\Scripts\activate
hello_world
sample code. Then, install dependencies:
cd YOUR_SAMPLE_CODE_DIR
pip install -r requirements.txt
python main.py
http://localhost:8080
To deploy your web service to App Engine, you need an app.yaml
file. This configuration file defines your web service's settings for App Engine.
To configure your web service for deployment to App Engine, create your app.yaml
file in the root directory of your project, for example building-an-app
:
Notice that for this simple web service, your app.yaml
file needs to define only the runtime setting and handlers for static files.
For more complicated web services, you can configure additional settings in your app.yaml
, like scaling, additional handlers, and other application elements like environment variables and service names. For more information and a list of all the supported elements, see the app.yaml
reference.
Now that you've configured, created, and tested your web service, you can deploy this version of your web service to App Engine.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["This guide provides instructions for creating and testing a Python web service using Flask, which serves a static HTML file and placeholder data."],["The web service's file structure includes `app.yaml`, `main.py`, `requirements.txt`, a `static/` directory for CSS and JavaScript, and a `templates/` directory for the HTML file."],["Before deploying the service, you should set up a local Python 3 environment, install required dependencies using `pip`, and test the application locally by running `python main.py` and navigating to `http://localhost:8080` in a browser."],["Deploying to Google App Engine requires an `app.yaml` file that specifies the Python runtime and defines handlers for static files, with more settings available for complex services."],["For new Python web services on Google Cloud, it's recommended to start with Cloud Run instead of App Engine, for which there is a provided quickstart link."]]],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4