我正在观看一个教程,以获得一个基本的网络应用程序说"你好,世界" 但由于某种原因,我不明白,我得到了这个 " localhost页面无效 localhost目前无法处理此请求。"
这就是我所做的。 1.我为python安装了Google App Engine SDK。 我创建了两个这样的文件:
main.py
import webapp2
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.write('Hello, World!')
app = webapp2.WSGIApplication([
('/', MainPage),
], debug=True)
的app.yaml
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: helloworld.app
我没写过这些。这些是在谷歌应用程序引擎网站上给出的。
我尝试了两种不同的方法来运行它。
我使用了这个命令:dev_appserver.py。 这就是我得到的:
INFO 2016-04-02 04:28:02,071 sdk_update_checker.py:229] Checking for updates to the SDK.
INFO 2016-04-02 04:28:02,949 sdk_update_checker.py:257] The SDK is up to date.
INFO 2016-04-02 04:28:02,982 api_server.py:205] Starting API server at: http://localhost:50345
INFO 2016-04-02 04:28:02,988 dispatcher.py:197] Starting module "default" running at: http://localhost:8080
INFO 2016-04-02 04:28:02,989 admin_server.py:116] Starting admin server at: http://localhost:8000
当我进入" http://localhost:8000"在chrome上,我收到此错误信息: " localhost页面无效 localhost目前无法处理此请求。"
这是我在终端上的错误消息
ERROR 2016-04-02 04:43:47,109 wsgi.py:263]
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
ImportError: No module named helloworld
INFO 2016-04-02 04:43:47,114 module.py:787] default: "GET / HTTP/1.1" 500 -
ERROR 2016-04-02 04:43:47,602 wsgi.py:263]
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
ImportError: No module named helloworld
INFO 2016-04-02 04:43:47,606 module.py:787] default: "GET / HTTP/1.1" 500 -
我做错了什么? 谢谢。
答案 0 :(得分:1)
您遇到的问题是您已将模块命名为main.py
,但告诉GAE服务器查找名为helloworld
的模块。该模块不存在,因此无法加载该站点。
将您的main.py
文件重命名为helloworld.py
,或将app.yaml
更改为main.app
而不是helloworld.app
。
答案 1 :(得分:-2)
webapp2没有很好的介绍。如果您是网络框架的新手,我会恳请您从这个框架开始。
https://github.com/iogf/untwisted
它是一个事件驱动的库,它实现了一组插件,其中一个是一个微型Web框架,其设计类似于烧瓶但速度更快。