Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python ImportError: No module named main in Google app engine project

I have the following app.yaml file

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"

And the file 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)

The files that I should deploy are just html files or js or images, I get the following error after compiling the app:

raise ImportError('%s has no attribute %s' % (handler, name)) ImportError: has no attribute app


Solved: I had to call "app" not "application" !

    app = webapp2.WSGIApplication([('/.*', MainPage)],
                                     debug=True)
like image 258
T-student Avatar asked Dec 27 '22 06:12

T-student


1 Answers

You've called the file index.py, not main.py. Either rename it, or use index.app in the yaml.

like image 118
Daniel Roseman Avatar answered Apr 08 '23 22:04

Daniel Roseman