How can i use script in sub folders on gae?

2019-07-20 06:45发布

when i was about to write a sub module for my app, i'd like to put all the stuffs in a sub folder like /foo, and i give the script the name foo.py and in it there's a

app = webapp2.WSGIApplication([('/foo/', Index)])

then it comes to

Fatal error when loading application configuration:
threadsafe cannot be enabled with CGI handler: foo/foo.app
  in "/home/***/workspace/***/app.yaml", line 23, column 20

then i set it to false, it becomes error 500

ImportError: Could not find module foo.foo.app

my app.yaml is like

application: ***
version: alpha
runtime: python27
api_version: 1
threadsafe: false

handlers:
- url: /static
  static_dir: static

- url: /admin.*
  script: admin.app
  login: admin

- url: /foo
  script: foo/foo.app

- url: /.*
  script: index.app

3条回答
该账号已被封号
2楼-- · 2019-07-20 07:15

finally i solved like this:

  1. add __init__.py in the folder foo/, leave it empty.
  2. change foo/foo.app to foo.foo.app

and it seems has nothing to do with threadsafe, i changed it to true and it's still working.

查看更多
Ridiculous、
3楼-- · 2019-07-20 07:23

In order to flag your folder as a package in python, the only thing you have to do is to create an empty __init__.py file in that folder (note two underscores on both sides of init).

Then in order to use your code from another file, you have to import the relevant file.

import foo where foo stands for your filename in your folder (foo.py)

查看更多
Luminary・发光体
4楼-- · 2019-07-20 07:27

The foo folder must be a python package so as to work. Thus, just add an __init__.py inside it and it should be ok.

查看更多
登录 后发表回答