Я пытался развернуть свой проект django с помощью gcp, но продолжаю получать серию ошибок. проект выполняется локально, но не запускается даже после успешного выполнения 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/'
app.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