0

我一直在研究 GAE - 尝试创建一个新项目:命令出错

abid@abid-webdev:~/Documents/GAE_projects$ python google_appengine/dev_appserver.py exe1.py/

错误

INFO 2013-10-29 08:27:57,104 module.py:608] 默认值:“GET / HTTP/1.1”500 - 错误 2013-10-29 08:29:43,171 wsgi.py:262] Traceback(最近的调用最后):文件“/home/abid/Documents/GAE_projects/google_appengine/google/appengine/runtime/wsgi.py”,第 239 行,在 Handle handler = _config_handle.add_wsgi_middleware(self._LoadHandler()) 文件“/home/abid /Documents/GAE_projects/google_appengine/google/appengine/runtime/wsgi.py”,第 298 行,在 _LoadHandler 处理程序中,路径,err = LoadObject(self._handler) 文件“/home/abid/Documents/GAE_projects/google_appengine/google/ appengine/runtime/wsgi.py”,第 84 行,在 LoadObject obj = import(path[0]) ImportError: No module named helloworld INFO 2013-10-29 08:29:43,191 module.py:608] 默认值:"GET / HTTP/1.1" 500 - ERROR 2013-10-29 08:29: 51,775 wsgi.py:262] Traceback(最近一次调用最后):文件“/home/abid/Documents/GAE_projects/google_appengine/google/appengine/runtime/wsgi.py”,第 239 行,在句柄处理程序 = _config_handle.add_wsgi_middleware( self._LoadHandler()) 文件“/home/abid/Documents/GAE_projects/google_appengine/google/appengine/runtime/wsgi.py”,第 298 行,_LoadHandler 处理程序,路径,err = LoadObject(self._handler) 文件“/ home/abid/Documents/GAE_projects/google_appengine/google/appengine/runtime/wsgi.py”,第 84 行,在 LoadObject obj = import (path[0]) ImportError: No module named helloworld

1) ImportError: No module named helloworld-> 我注意到了这个错误

  • 目前正在处理这个项目exercise1,从以前的项目中复制了 app.yaml 文件helloworld/

  • 检查app.yaml,内容如下:

应用程序:您的应用程序 ID 版本:1 运行时:python27 api_version:1 线程安全:true

处理程序:- url:/.*

脚本:helloworld.application>

2) 在 google URL -> 对路径匹配正则表达式 /.*(所有 URL)的 URL 的每个请求都应由 helloworld 模块中的应用程序对象处理。

3)我的目录结构

abid@abid-webdev:~/Documents/GAE_projects$ ls

练习
1 helloworld
google_appengine

问题:

如何修改我的 app.yaml 以与我的其他项目一起使用,例如练习 1?

感谢你的帮助。

4

1 回答 1

2

让我们从顶部开始!

对于您的新项目,您需要在练习 1 目录中具有以下结构:

Directory: exercise1
  File: app.yaml
  File: exercise1.py

在 app.yaml 你需要这样的东西:

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

handlers:
- url: /.*
  script: exercise1.application

“script: exercise1.application”这一行告诉它要使用哪个文件(在本例中为 exercise1.py)以及要使用的 WSGI 处理程序实例(在本例中为 application)

在 exercise1.py 你需要这样的东西:

import webapp2


class HomePage(webapp2.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.write('Hey Y'all!')

application = webapp2.WSGIApplication([
    ('/', HomePage),
], debug=True)

在这里你可以看到我们在 app.yaml 中提到的应用程序。

一旦你有了这个基本结构,你需要启动开发应用服务器。你在问题中的做法是不正确的:

您需要使用目录“exercise1”运行 dev_appserver,而不是 python 文件。

假设 Google App Engine sdk 仍位于“~/Documents/GAE_projects/google_appengine”,从exercise1 目录运行以下命令:

python ~/Documents/GAE_projects/google_appengine/dev_appserver.py ./

这将启动 dev_appserver.py 脚本,告诉它使用当前目录(这就是“./”的意思)。

如果您遵循这一点,那么您应该开始行动了!

于 2013-11-08T22:49:03.257 回答