我一直在尝试使用 gcp 部署我的 django 项目,但我不断收到一系列错误。gcloud app deploy
该项目在本地运行,但即使在成功运行后也不会运行。如果我尝试访问该网站,我会得到server error (500)
settings.py
if os.getenv('GAE_APPLICATION', None):
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'HOST': '/cloudsql/connection name',
'USER': ' user',
'PASSWORD': 'project_password',
'NAME': 'instance name',
}
}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'portfolio',
'USER': 'postgres',
'PASSWORD': 'local db password',
'HOST': 'localhost',
'PORT': 5432,
}
}
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},]
STATIC_URL = 'https://storage.googleapis.com/newinstance_buc/static/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'static/')
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')
# STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)
MEDIA_URL = '/media/'
应用程序.yaml
env: flex
entrypoint: gunicorn -b :$PORT mysite.wsgi
env_variables:
SECRET_KEY: secret_key
beta_settings:
cloud_sql_instances: connection_name=tcp:5432
runtime_config:
python_version: 3
automatic_scaling:
min_num_instances: 1
max_num_instances: 2
以下是错误日志 错误报告中的错误报告
File "/layers/google.python.pip/pip/gunicorn/arbiter.py", line 583, in spawn_worker
worker.init_process()
File "/layers/google.python.pip/pip/gunicorn/workers/gthread.py", line 92, in init_process
super().init_process()
File "/layers/google.python.pip/pip/gunicorn/workers/base.py", line 119, in init_process
self.load_wsgi()
File "/layers/google.python.pip/pip/gunicorn/workers/base.py", line 144, in load_wsgi
self.wsgi = self.app.wsgi()
File "/layers/google.python.pip/pip/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/layers/google.python.pip/pip/gunicorn/app/wsgiapp.py", line 49, in load
return self.load_wsgiapp()
File "/layers/google.python.pip/pip/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
return util.import_app(self.app_uri)
File "/layers/google.python.pip/pip/gunicorn/util.py", line 358, in import_app
mod = importlib.import_module(module)
File "/opt/python3.8/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'main'
如果我尝试进行一些更改,则会出现另一个错误
Traceback (most recent call last):
File "/env/lib/python3.6/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
self.connect()
File "/env/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/env/lib/python3.6/site-packages/django/db/backends/base/base.py", line 197, in connect
self.connection = self.get_new_connection(conn_params)
File "/env/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/env/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 185, in get_new_connection
connection = Database.connect(**conn_params)
File "/env/lib/python3.6/site-packages/psycopg2/__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: Connection refused