按照推送部署教程(https://cloud.google.com/tools/repo/push-to-deploy-quickstart)后,每次运行作业时,我都会收到以下错误。我的项目是一个预先存在的django项目,我使用本教程https://cloud.google.com/appengine/docs/python/cloud-sql/django
进行了转换我需要使用第三方库,包括django 1.6。在查看错误后,我似乎只能在使用webmaven的代码https://stackoverflow.com/a/25833304/805767后才能包含库,因为django版本已从django-0.96更改
错误
错误:失败:配置不当(请求的设置 DEFAULT_INDEX_TABLESPACE,但未配置设置。你必须 要么定义环境变量DJANGO_SETTINGS_MODULE,要么调用 在访问设置之前的settings.configure()。)
错误:失败:配置不当(请求设置CACHES,但是 设置未配置。您必须定义环境 变量DJANGO_SETTINGS_MODULE或之前调用settings.configure() 访问设置。)
堆栈跟踪
======================================================================
ERROR: Failure: ImproperlyConfigured (Requested setting CACHES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 414, in loadTestsFromName
addr.filename, addr.module)
File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 47, in importFromPath
return self.importFromDir(dir_path, fqname)
File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 94, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "/var/jenkins/workspace/myapp_job/lib/rest_framework/tests/test_urlpatterns.py", line 4, in <module>
from django.test import TestCase
File "/var/jenkins/workspace/myapp_job/lib/django/test/__init__.py", line 5, in <module>
from django.test.client import Client, RequestFactory
File "/var/jenkins/workspace/myapp_job/lib/django/test/client.py", line 11, in <module>
from django.contrib.auth import authenticate, login, logout, get_user_model
File "/var/jenkins/workspace/myapp_job/lib/django/contrib/auth/__init__.py", line 6, in <module>
from django.middleware.csrf import rotate_token
File "/var/jenkins/workspace/myapp_job/lib/django/middleware/csrf.py", line 14, in <module>
from django.utils.cache import patch_vary_headers
File "/var/jenkins/workspace/myapp_job/lib/django/utils/cache.py", line 26, in <module>
from django.core.cache import get_cache
File "/var/jenkins/workspace/myapp_job/lib/django/core/cache/__init__.py", line 69, in <module>
if DEFAULT_CACHE_ALIAS not in settings.CACHES:
File "/var/jenkins/workspace/myapp_job/lib/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/var/jenkins/workspace/myapp_job/lib/django/conf/__init__.py", line 47, in _setup
% (desc, ENVIRONMENT_VARIABLE))
ImproperlyConfigured: Requested setting CACHES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
======================================================================
ERROR: Failure: ImproperlyConfigured (Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 414, in loadTestsFromName
addr.filename, addr.module)
File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 47, in importFromPath
return self.importFromDir(dir_path, fqname)
File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 94, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "/var/jenkins/workspace/myapp_job/lib/rest_framework/tests/test_validation.py", line 3, in <module>
from django.db import models
File "/var/jenkins/workspace/myapp_job/lib/django/db/models/__init__.py", line 5, in <module>
from django.db.models.query import Q
File "/var/jenkins/workspace/myapp_job/lib/django/db/models/query.py", line 17, in <module>
from django.db.models.deletion import Collector
File "/var/jenkins/workspace/myapp_job/lib/django/db/models/deletion.py", line 4, in <module>
from django.db.models import signals, sql
File "/var/jenkins/workspace/myapp_job/lib/django/db/models/sql/__init__.py", line 4, in <module>
from django.db.models.sql.subqueries import *
File "/var/jenkins/workspace/myapp_job/lib/django/db/models/sql/subqueries.py", line 12, in <module>
from django.db.models.sql.query import Query
File "/var/jenkins/workspace/myapp_job/lib/django/db/models/sql/query.py", line 22, in <module>
from django.db.models.sql import aggregates as base_aggregates_module
File "/var/jenkins/workspace/myapp_job/lib/django/db/models/sql/aggregates.py", line 9, in <module>
ordinal_aggregate_field = IntegerField()
File "/var/jenkins/workspace/myapp_job/lib/django/db/models/fields/__init__.py", line 116, in __init__
self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
File "/var/jenkins/workspace/myapp_job/lib/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/var/jenkins/workspace/myapp_job/lib/django/conf/__init__.py", line 47, in _setup
% (desc, ENVIRONMENT_VARIABLE))
ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
appengine_config.py
"""This file is loaded when starting a new application instance."""
import os
import site.addsitedir
import sys.path
# os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")
# os.environ["DJANGO_SETTINGS_MODULE"] = 'myapp.settings'
dirname = 'lib'
dirpath = os.path.join(os.path.dirname(__file__), dirname)
# split path after 1st element ('.') so local modules are always found first
sys.path, remainder = sys.path[:1], sys.path[1:]
# add `lib` subdirectory as a site directory, so our `main` module can load
# third-party libraries.
site.addsitedir(dirpath)
# append the rest of the path
sys.path.extend(remainder)
的app.yaml
application: myapp
version: 1
runtime: python27
api_version: 1
threadsafe: true
env_variables:
DJANGO_SETTINGS_MODULE: 'myapp.settings'
如何解决这些错误?
编辑添加了目录结构
C:.
│ .gitignore
│ app.yaml
│ appengine_config.py
│ generate_fixtures.py
│ manage.py
│ print.txt
│ README.md
│ requirements.txt
│ __init__.py
├───apps
├───fixtures
├───lib
│ __init__.py
├───myapp
│ app.py
│ app.pyc
│ settings.py
│ settings.pyc
│ urls.py
│ urls.pyc
│ views.py
│ wsgi.py
│ wsgi.pyc
│ wsgi_for_apache.py
│ __init__.py
│ __init__.pyc