谷歌应用引擎标准和 Pyramid¶
可以运行 Pyramid 应用于 Google App Engine. This tutorial is written in terms of using the command line on a UNIX system. It should be possible to perform similar actions on a Windows system. This tutorial also assumes you've already installed and created a Pyramid application, and that you have a Google App Engine account.
安装程序¶
首先,我们需要创建一些文件,以便应用程序引擎能够与我们的项目正确通信。
创建包含以下内容的文件。
requirements.txt
Pyramid waitress pyramid_debugtoolbar pyramid_chameleon
main.py
from pyramid.paster import get_app, setup_logging ini_path = 'production.ini' setup_logging(ini_path) application = get_app(ini_path, 'main')
appengine_config.py
from google.appengine.ext import vendor vendor.add('lib')
app.yaml
1application: application-id 2version: version 3runtime: python27 4api_version: 1 5threadsafe: false 6 7handlers: 8- url: /static 9 static_dir: pyramid_project/static 10- url: /.* 11 script: main.application
使用以下值配置此文件:
将“应用程序ID”替换为应用程序引擎应用程序的ID。
将“version”替换为要部署的版本。
替换的定义中的“Pyramid项目”
static_dir
Static Assets的父目录名。如果您的Static Assets在根目录中,那么您可以只放置“static”。
For more details about
app.yaml
见 app.yaml Reference .安装依赖项。
$ pip install -t lib -r requirements.txt
局部运行¶
此时,您应该拥有在本地运行 Pyramid 应用程序所需的一切。 dev_appserver
. Assuming you have appengine in your $PATH
:
$ dev_appserver.py app.yaml
还有 voilà!你应该有一个完美运行的 Pyramid 应用程序通过谷歌应用引擎在你的本地机器上。
部署¶
如果您已在本地成功启动了应用程序,请使用单个命令部署。
$ appcfg.py update app.yaml
你的 Pyramid 应用程序现在已经在世界上运行了!您可以通过导航到您的域名、通过“<applicationid>.appspot.com”访问它,或者如果您在默认值之外指定了一个版本,那么它将是“<version dot applicationid>.appspot.com”。