我一直在研究GAE - 尝试创建一个新项目:并在命令上获得错误
abid@abid-webdev:~/Documents/GAE_projects$ python google_appengine/dev_appserver.py exe1.py/
ERROR
INFO 2013-10-29 08:27:57,104 module.py:608]默认值:“GET / HTTP / 1.1”500 - ERROR 2013-10-29 08:29:43,471 wsgi.py:262] Traceback(最近一次调用最后一次): 在Handle中输入文件“/home/abid/Documents/GAE_projects/google_appengine/google/appengine/runtime/wsgi.py”,第239行 handler = _config_handle.add_wsgi_middleware(self._LoadHandler()) 在_LoadHandler中输入文件“/home/abid/Documents/GAE_projects/google_appengine/google/appengine/runtime/wsgi.py”,第298行 handler,path,err = LoadObject(self._handler) 在LoadObject中输入文件“/home/abid/Documents/GAE_projects/google_appengine/google/appengine/runtime/wsgi.py”,第84行 obj = 导入(路径[0]) ImportError:没有名为helloworld的模块 INFO 2013-10-29 08:29:43,491 module.py:608]默认值:“GET / HTTP / 1.1”500 - ERROR 2013-10-29 08:29:51,775 wsgi.py:262] Traceback(最近一次调用最后一次): 在Handle中输入文件“/home/abid/Documents/GAE_projects/google_appengine/google/appengine/runtime/wsgi.py”,第239行 handler = _config_handle.add_wsgi_middleware(self._LoadHandler()) 在_LoadHandler中输入文件“/home/abid/Documents/GAE_projects/google_appengine/google/appengine/runtime/wsgi.py”,第298行 handler,path,err = LoadObject(self._handler) 在LoadObject中输入文件“/home/abid/Documents/GAE_projects/google_appengine/google/appengine/runtime/wsgi.py”,第84行 obj = 导入(路径[0]) ImportError:没有名为helloworld的模块
1)ImportError: No module named helloworld
- >我注意到了这个错误
目前正在处理此项目exercise1
,复制了之前项目中的app.yaml文件helloworld/
检查了app.yaml,其内容如下:
应用程序:your-app-id 版本:1 runtime:python27 api_version:1 threadsafe: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?
感谢所有人的帮助。
答案 0 :(得分:2)
让我们从顶部开始吧!
对于您的新项目,您需要在exercise1目录中包含此结构:
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 Handler实例(在本例中为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中提到的应用程序。
一旦有了这个基本结构,就需要启动dev appserver。你在问题中这样做的方式是不正确的:
您需要使用目录“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脚本,告诉它使用当前目录(这是“./”的意思)。
如果你遵循这个,那么你应该起来滚动!