【问题标题】:How can we deploy a django app onn google cloud?我们如何在谷歌云上部署 django 应用程序?
【发布时间】:2018-04-24 15:51:12
【问题描述】:

我在谷歌控制台上部署开发的 django 应用程序时遇到问题。 首先,它将应用程序的所有文件重命名为某个随机名称。此外,当我尝试访问网站 .appspot.com 时,出现内部错误。

已创建 app.yaml 文件:

# [START runtime]
runtime: python27
entrypoint: gunicorn -b :$PORT mysite.wsgi
threadsafe: true
# [END runtime]

handlers:
- url: /static
  static_dir: website/static

- url: /.*
  script: main.application

libraries:

- name: django
  version: 1.11

还创建了 appengine_cofig.py 文件:

# Copyright 2015 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# [START vendor]
from google.appengine.ext import vendor

vendor.add('lib')
# [END vendor]

提前感谢您的帮助....

【问题讨论】:

  • 您帖子中的信息不足,无法真正为您提供很大帮助。突出的一件事是您将灵活环境中的语法与标准环境相结合(entrypoint 仅适用于灵活环境)。
  • 从初学者的角度来看...如何让我的 django 网站在 google 应用引擎上启动并运行???

标签: python django google-app-engine deployment app.yaml


【解决方案1】:

作为一个完整的初学者,我建议您按照此处的 google 文档 (https://cloud.google.com/python/django/appengine) 逐步注意:

  1. Django 默认数据库是 sqlite3,您必须将其更改为 mysql,建议您在创建 Django 应用程序的一开始就这样做。我建议按照这个 youtube 视频 (https://www.youtube.com/watch?v=s16p32pndK0) 中的说明进行操作
  2. 您的 app.yaml 文件应如下所示;

runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: /static
  static_dir: static/
  application_readable: True
- url: .*
  script: yourapplication.wsgi.application

# Only pure Python libraries can be vendored
# Python libraries that use C extensions can
# only be included if they are part of the App Engine SDK 
# Using Third Party Libraries: https://cloud.google.com/appengine/docs/python/tools/using-libraries-python-27
libraries:
- name: MySQLdb
  version: 1.2.5
- name: django
  version: "1.11"
- name: ssl
  version: latest
# [END django_app]
 
# Google App Engine limits application deployments to 10,000 uploaded files per
# version. The skip_files section allows us to skip virtual environment files
# to meet this requirement. The first 5 are the default regular expressions to
# skip, while the last one is for all env/ files.
skip_files:
- ^(.*/)?#.*#$
- ^(.*/)?.*~$
- ^(.*/)?.*\.py[co]$
- ^(.*/)?.*/RCS/.*$
- ^(.*/)?\..*$
- ^env/.*$

我也是一个初学者,我刚刚设法将我的应用程序部署到 GAE,一切顺利。

【讨论】:

猜你喜欢
  • 2020-04-12
  • 2020-09-06
  • 2019-09-15
  • 2017-05-24
  • 2020-11-22
  • 2015-12-24
  • 1970-01-01
  • 2016-10-29
  • 2017-05-14
相关资源
最近更新 更多