Python ImportError:Google app引擎项目中没有名为main的模块

T-s*_*ent 4 python google-app-engine

我有以下app.yaml文件

application: gtryapp
version: 1
runtime: python27
api_version: 1
threadsafe: yes

handlers:

- url: /images/(.*\.(gif|png|jpg))
  static_files: static/img/\1
  upload: static/img/(.*\.(gif|png|jpg))

- url: /css/(.*\.css)
  mime_type: text/css
  static_files: static/css/\1
  upload: static/css/(.*\.css)

- url: /js/(.*\.js)
  mime_type: text/javascript
  static_files: static/js/\1
  upload: static/js/(.*\.js)

- url: /(.*\.html)
  mime_type: text/html
  static_files: static/\1
  upload: static/(.*\.html)

- url: .*
  script: main.app


libraries:

- name: webapp2
  version: "2.5.2"
Run Code Online (Sandbox Code Playgroud)

和文件app.py:

import webapp2

class MainPage(webapp2.RequestHandler):
def get(self):
    if self.request.url.endswith('/'):
        path = '%sindex.html'%self.request.url
    else:
        path = '%s/index.html'%self.request.url

    self.redirect(path)


    application = webapp2.WSGIApplication([('/.*', MainPage)],
                                     debug=True)
Run Code Online (Sandbox Code Playgroud)

我应该部署的文件只是html文件或js或图像,编译应用程序后出现以下错误:

引发ImportError('%s没有属性%s'%(处理程序,名称))ImportError:没有属性应用程序


解决了:我不得不称"app"而不是"应用程序"!

    app = webapp2.WSGIApplication([('/.*', MainPage)],
                                     debug=True)
Run Code Online (Sandbox Code Playgroud)

Dan*_*man 6

你已经调用了文件index.py,而不是main.py. 重命名,或index.app在yaml中使用.