如何使用带有Python的Google App Engine开发服务器运行两个版本的应用程序

问题描述 投票:0回答:1

我使用的是Ubuntu Server 13.10和Python 2.7。

我想有两个版本的App Engine应用程序:admin和默认版本。 我已经定义了这两个版本。 目前,这是我的app.yaml文件:

application: application-id
version: 1
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /css
  static_dir: css
- url: /js
  static_dir: js
- url: /
  script: python.MainPage.application
- url: /test.*
  script: gaeunit.application

libraries:
- name: webapp2
  version: latest
- name: jinja2
  version: latest


version: admin
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /css
  static_dir: css
- url: /js
  static_dir: js
- url: /.*
  script: python.MainPage.application
  login: admin
  auth_fail_action: unauthorized
- url: /test.*
  script: python.MainPage.appication

libraries:
- name: webapp2
  version: latest
- name: jinja2
  version: latest

当我将此代码部署到App Engine时,它按预期工作。 但是,如果我尝试使用Google Cloud SDK中的dev_appserver.py运行它,则会因此追溯而失败:

Traceback (most recent call last):
  File "/home/katie/google-cloud-sdk/platform/google_appengine/dev_appserver.py", line 82, in <module>
    _run_file(__file__, globals())
  File "/home/katie/google-cloud-sdk/platform/google_appengine/dev_appserver.py", line 78, in _run_file
    execfile(_PATHS.script_file(script_name), globals_)
  File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 902, in <module>
    main()
  File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 895, in main
    dev_server.start(options)
  File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 672, in start
    options.yaml_files)
  File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/application_configuration.py", line 556, in __init__
    module_configuration = ModuleConfiguration(yaml_path)
  File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/application_configuration.py", line 82, in __init__
    self._yaml_path)
  File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/application_configuration.py", line 272, in _parse_configuration
    return appinfo_includes.ParseAndReturnIncludePaths(f)
  File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/api/appinfo_includes.py", line 63, in ParseAndReturnIncludePaths
    appyaml = appinfo.LoadSingleAppInfo(appinfo_file)
  File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/api/appinfo.py", line 1826, in LoadSingleAppInfo
    listener.Parse(app_info)
  File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/api/yaml_listener.py", line 226, in Parse
    self._HandleEvents(self._GenerateEventParameters(stream, loader_class))
  File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/api/yaml_listener.py", line 177, in _HandleEvents
    raise yaml_errors.EventError(e, event_object)
google.appengine.api.yaml_errors.EventError: Duplicate attribute 'version'.
  in "aerobic-arcade-514/default/app.yaml", line 24, column 10
python google-app-engine google-cloud-platform
1个回答
2
投票

您可以在两个不同的端口上启动两个不同的开发应用服务器,只需使用--port=参数覆盖默认端口,但是您需要将两个app.yaml文件分开,而不是使用与您相同的文件。 运行dev_appserver.py ,请使用配置文件作为最终参数,而不是目录(默认为app.yaml )。

例如:

dev_appserver.py --port=8888 app_one.yaml
dev_appserver.py --port=9999 app_two.yaml

在测试之后和部署之前,请确保保留名为app.yaml的最终文件; 否则,您将无法完成此过程。

热门问题
推荐问题
最新问题