Deploy a Django application on Google App Engine (Python3)

Introduction (Caution)

In this article, I wrote about how to publish Django application on the Internet using GAE's flexible environment, but GAE's flexible environment is __ "beta version" as of July 10, 2017 (Monday). It is __. The tutorial page also says __ "We do not recommend using it in a production environment." __, so please read this article based on that.

reference: Run Django on App Engine Flexible Environment (


Recently, I personally develop a web application on Django, and when I publish it, Azure Web App I'm trying out some PaaS services such as -web / app-service-web-overview) and Google App Engine. In this article, I would like to write the record up to deployment when using Google App Engine (hereinafter GAE), focusing mainly on the points I was addicted to.

When it comes to Django (Python3) on GAE, I get the impression that there wasn't much information available on Google, so I hope it helps people who are just as addicted to it.

Cause of addiction

Looking back, there are two reasons why I was addicted to it.

  1. Cannot run Python 3 in "standard environment"
  2. It is difficult to grasp the whole picture of the work, and it is easy to get into the state of "what are you doing now?"

(I'm new to Django and GAE, so maybe for those who are used to it, there may be something that is "natural".)

Then, I will write the details below.

Cannot run Python 3 in "standard environment"

In the first place, GAE has __ "standard environment" __ and __ "flexible environment" __, each of which has different mechanisms, restrictions, and uses. I was really into it because I didn't know this.

If you think "I'm going to deploy a Django application with GAE!", I think I'll try google with "Django Google App Engine" first. (maybe)

Then, the following page will hit the top.

Running Django on App Engine standard environment

Oh, the official tutorial was a hit. This seems to work if you follow the steps!

Please wait a moment for you (I am) there. The title of this page is "Running Django on App Engine __ Standard Environment __".

And then, if you look at this Django Getting Started Guide page (it's one level higher than the previous page) ), In the column of the case where the standard environment cannot be used __

Requires Python 3 Requires a system library that cannot be used in App Engine's standard Python environment

It is described as.

In other words, if you want to write an application in Python3 or develop using "a system library that cannot be used in the standard Python environment of App Engine", this standard environment cannot be used.

In other words, even if you proceed according to the page for "Standard environment" earlier, you will be addicted to the restrictions around that. I didn't notice this and struggled to get Python 3 running and libraries installed in a standard environment.

A detailed explanation of the difference between the standard environment and the flexible environment is summarized on the following page.

App Engine Flexible Environment for App Engine Standard Environment Users (

In short, since the operation method as a platform is completely different, it seems that it is not a flexible environment if you simply want to use Python 3 by using it properly. It seems that it is necessary to design the system after understanding this area properly.

This time I would like to deploy the system written in Python 3 to GAE, so I will proceed with the work referring to the following page.

Run Django on App Engine Flexible Environment (

It is difficult to grasp the whole picture of the work, and it is easy to get into the state of "what are you doing now?"

Now, once you find a tutorial page to refer to, you can rely on it to proceed with your work.

However, this procedure is quite long, and if you actually do this from 1, you will gradually fall into the state of "What are you doing for what?"

In such a case, as a guide for confirming your current location, it is very effective for mental health to understand what kind of procedure is required from the start of work to deployment, so I will summarize it here.

The items are as follows.

  1. Set up an account to use Google Cloud Platform
  2. Create a Google Cloud Platform project
  3. Install Google Cloud SDK
  4. Prepare the database (Cloud SQL)
  5. Clone the sample project and try deploying it
  6. Deploy your application

Let's take a closer look at each one. The specific work procedure is as described in the document, so I will omit it. The purpose here is to get an overall picture.

Set up an account to use Google Cloud Platform

GAE is one of the cloud services provided by Google called Google Cloud Platform (GCP). Just as AWS has various services such as EC2, Lambda, and S3, GCP also has various services such as GAE, Cloud Storage (which will come out later), and Big Query. GAE is one of them, isn't it?

Therefore, first of all, set up an account (you can use your Gmail account as it is) to start using GCP. Please also set the billing here.

Create a Google Cloud Platform project

In GCP, various services are combined into one system in units called "projects". First, let's create a project. Follow the tutorial to open the GCP console page and create your project.

The ID of the project created here will be used later, so it will be easier to work if you write it down as text somewhere.

Install Google Cloud SDK

To operate each GCP service including GAE from the command line, you need to install Google Cloud SDK.

There are some things to do, such as installing the command itself, setting the account, checking the operation, etc., so this is also the procedure (separate page I will proceed one by one while watching mac)).

Prepare the database (Cloud SQL)

Neither Django nor Rails can continue to use SQLite, which was used in the development environment, in the production environment. When you deploy the application, you need to prepare some RDB and rewrite the settings to connect to it.

GAE explains how to use Cloud SQL, which is one of the same GCP services, as a tutorial.

There are many things to do, such as enabling Cloud SQL on the GCP console, creating an instance, creating a root user, controlling access and creating an environment where you can log in, so don't get lost here either. Please be careful.

In addition, it seems that there are 1st generation and 2nd generation in the instance of Cloud SQL, but when using it in a flexible environment, it seems that the 2nd generation is always used.

After completing various settings, describe the settings in the file of the sample project cloned in the next step so that the application can connect to the DB.

Clone the sample project and try deploying it

When I try to deploy my application suddenly, it becomes difficult to isolate the cause when an error occurs, such as the relationship between the library version, the contents of the configuration file required for GAE, and the inadequate preparation for deployment to GAE in the first place. I will.

First, clone the sample project as described in the procedure, change only the DB connection settings, and deploy it to the GAE flexible environment once.

After confirming that the prepared Hello World page is displayed without any problem, proceed to the next step.

Deploy your application

After doing so, port your application to the sample project you just deployed, deploy it, and check the operation little by little, and confirm that your application works on the Internet without any problems.

Generally, you will get an error different from the local one due to the difference in the version of Django or Python itself, the difference in the library, the difference in the DB, etc., so it is recommended to proceed little by little to make it easier to isolate the cause.

In case of an error that the library cannot be found, add the description of the library you are using to requirements.txt with pip freeze> requirements.txt and forget to have it installed when you deploy to GAE. Let's not.

With this, we can finally see the flow of application development → production release. It's good to see your application working non-locally.

After this, you will feel like repeating adding functions and deploying with the same procedure.

This time, I deployed based on the template project, but I understand the settings for the GAE environment described in ʻapp.yaml and` so that I can modify the settings to suit my application. I think it is also necessary to become.


This time, I focused on GAE, but before this trial and error, I experienced the same trial and error on Azure Web App, and as a result, I could not deploy successfully.

Once the application can be deployed, the PaaS service is easy to modify from there, but before that, you have to understand various PaaS-specific mechanisms, restrictions, and setting methods. , "Hello World!" I got a little hard impression.

In addition, the "GAE flexible environment Django (Python3)" used this time was lost because there were few people doing it in the first place, and even if I googled when a problem occurred, I could not find the right information. It was one of the big factors to become.

I thought that I should write in this article individual errors and solutions that occurred during actual work, but I did not write down the contents properly, or when I tried to solve it, it was my simple work mistake. I will omit it because I did it. If you have any specific problems, please comment. (I don't know if I can solve it, but ...)

Recommended Posts

Deploy a Django application on Google App Engine (Python3)
How to use Django on Google App Engine / Python
[Python] Run Flask on Google App Engine
Tweet (API 1.1) on Google App Engine for Python
How to deploy a Django application on Alibaba Cloud
PIL with Python on Windows 8 (for Google App Engine)
Deploy a Django app made with PTVS on Azure
Deploy a Django application with Docker
Deploy your Django application on Heroku
Implement a Django app on Hy
Use ndb.tasklet on Google App Engine
Deploy your Go app on Google App Engine with GitHub Actions
Deploy a Django application on EC2 with Nginx + Gunicorn + Supervisor
Until you run a Flask application on Google App Engine for the time being
Deploy the Django app on Heroku [Part 1]
Do you have any recommendations for a commentary book on Google App Engine / Python development?
Use external modules on Google App Engine
How to deploy a Django app on heroku in just 5 minutes
Use Django's ImageField on App Engine / Python
I can't deploy with google app engine
Building a development environment with Maven on Google App Engine [Java]
Until you deploy a SpringBoot project in Gradle on App Engine Flexible
(Python) Try to develop a web application using Django
How to build a Django (python) environment on docker
Google App Engine / Python development environment construction procedure (late 2014)
Try running a Django application on an nginx unit
Steps from installing Python 3 to creating a Django app
(Beginner) Basic usage of Datastore on Google App Engine
Getting Started with Google App Engine for Python & PHP
A memo about building a Django (Python) application with Docker
Runtime version of Google App Engine / Python Standard Environment
Deploy masonite app on Heroku 2020
(Failure) Deploy a web app made with Flask on heroku
Building a Python environment on Mac
If you know Python, you can make a web application with Django
Building a Python environment on Ubuntu
Create a Python environment on Mac (2017/4)
# 3 Build a Python (Django) environment on AWS EC2 instance (ubuntu18.04) part2
Settings when writing Google App Engine / Python apps in Intellij Idea
Create new application use python, django
Google App Engine development with Docker
python + django + scikit-learn + mecab (1) on heroku
Create and deploy a Django (PTVS) app using Azure Table storage
Java 1 1 support from Google App Engine
python + django + scikit-learn + mecab (2) on heroku
Deploy Flask app on heroku (bitterly)
Create a python environment on centos
Run python3 Django1.9 with mod_wsgi (deploy)
Build a web application with Django
Deploy the Flask app on Heroku
Make a scraping app with Python + Django + AWS and change jobs
How to deploy a web application on Alibaba Cloud as a freelancer
Deploy the Flask app on heroku
Launched a web application on AWS with django and changed jobs
Build a python3 environment on CentOS7
Using properties files with Flexible Environment Java 8 on Google App Engine
[Google App Engine] Flow from development environment construction to application creation
Build your Django app on Docker and deploy it to AWS Fargate
[Detailed version] Creating a comfortable Python environment with Google Compute Engine (Ubuntu 16.04)
Until you publish (deploy) a web application made with bottle on Heroku
Migrate Django applications running on Python 2.7 to Python 3.5