首页 > 解决方案 > 部署到 GCP 时,支持 mysql 的 Django 应用程序无法正常工作

问题描述

我正在尝试使用 MySQL 作为数据库创建示例 Django 应用程序,当我尝试在 GCP 上部署的同一个应用程序给出 500 错误时,它在本地工作正常。我在 GCP 中创建了 sql server 并起诉了相同的设置

它没有找到gunicorn,但我已经在requirments.txt.

2019-01-19 07:42:57 default[20190119t130429]  "GET /admin HTTP/1.1" 500
2019-01-19 07:42:58 default[20190119t130429]  /bin/sh: 1: exec: gunicorn: not found
2019-01-23 17:41:21 default[20190119t130429]  "GET /admin HTTP/1.1" 500
2019-01-23 17:41:22 default[20190119t130429]  /bin/sh: 1: exec: gunicorn: not found
2019-01-23 18:36:00 default[20190123t235752]  "GET /admin HTTP/1.1" 500
2019-01-23 18:36:00 default[20190123t235752]  /bin/sh: 1: exec: gunicorn: not found
2019-01-23 18:36:01 default[20190123t235752]  "GET /favicon.ico HTTP/1.1" 500
2019-01-23 18:36:02 default[20190123t235752]  /bin/sh: 1: exec: gunicorn: not found
2019-01-23 18:36:20 default[20190123t235752]  "GET /admin HTTP/1.1" 500
2019-01-23 18:36:20 default[20190123t235752]  /bin/sh: 1: exec: gunicorn: not found
2019-01-23 18:36:21 default[20190123t235752]  "GET /favicon.ico HTTP/1.1" 500
2019-01-23 18:36:21 default[20190123t235752]  /bin/sh: 1: exec: gunicorn: not found
**app.yaml**

runtime: python37
entrypoint: gunicorn -b :$PORT sqlreco.wsgi
#threadsafe: yes

handlers:
- url: /images
  static_dir: static/images
  http_headers:
    Access-Control-Allow-Origin: '*'

runtime_config:
 python_version: 3


**requirnaments.txt**

Django==2.1.5
djangorestframework==3.9.1
mysql==0.0.2
mysqlclient==1.4.1
pytz==2018.9
gunicorn==19.8.1

标签: pythonmysqldjangogoogle-app-enginegoogle-cloud-platform

解决方案


基于此错误:

ModuleNotFoundError: No module named 'main'

您的应用程序似乎没有main.py文件。如果您没有指定自定义入口点,则需要让这个文件带有一个名为的变量,该变量app对应于您的应用程序。

对于 Django,您可能只需要在以下位置执行以下操作main.py

from mysite.wsgi import application as app

mysite您的 Django 应用程序所在的目录的名称在哪里。


推荐阅读