您好,在 Google App Engine 中尝试从 python2.5/webapp 迁移到 python2.7.4/webapp2 时出现以下错误。
File "C:\main\main.py", in get
**compiled_template = template.Template(template_file.read())**
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\_internal\django\template\__init__.py", line 156, in __init__
if settings.TEMPLATE_DEBUG and origin is None:
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\_internal\django\conf\__init__.py", line 31, in __getattr__
assert self.holder, 'settings has not been configured in this thread'
AssertionError: settings has not been configured in this thread
这是完整的代码:
main.py 文件
import webapp2
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
try:
from google.appengine.dist import use_library
use_library('django', '1.2')
except:
pass
from django.conf import settings
_ = settings.TEMPLATE_DIRS
from google.appengine.ext.webapp import template
class Main(webapp2.RequestHandler):
def get(self):
template_values = {
'CURRENT_VERSION_ID': os.environ['CURRENT_VERSION_ID']
}
path = os.path.join(os.path.dirname(__file__), './src/main.html');
path = os.path.normpath(path);
template_file = open(path)
compiled_template = template.Template(template_file.read()) #THIS GIVES THE ERROR
template_file.close()
self.response.out.write(compiled_template.render(template.Context(template_values)))
return
app = webapp2.WSGIApplication(
[
('/', Main)
],
debug=True
)
app.yaml 文件
application: main
version: 1
runtime: python27
api_version: 1
threadsafe: true
derived_file_type:
- python_precompiled
libraries:
- name: yaml
version: "3.10"
- name: webob
version: "1.1.1"
- name: webapp2
version: "2.5.2"
- name: django
version: "1.2"
handlers:
- url: /.*
script: main.app
你能帮忙吗?谢谢!(请注意,给出错误的行在 webapp+python2.5 中运行良好。只有在迁移到 webapp2+python2.7.4 之后,我才开始看到此错误。)