Как настроить два ведра Google Storage Buckets для приложения Django: одно для файлов MEDIA, а другое для STATIC?
Вот ошибка, которую я получаю на главной странице моего приложения.
Your default credentials were not found. To set up Application Default Credentials, see https://cloud.google.com/docs/authentication/external/set-up-adc for more information.
#settings.py
from google.oauth2 import service_account
from google.cloud import storage
try:
# Load service account info from environment variables
service_account_info = {
"type": env("TYPE"),
"project_id": env("PROJECT_ID"),
"private_key_id": env("PRIVATE_KEY_ID"),
"private_key": env("PRIVATE_KEY"),
"client_email": env("CLIENT_EMAIL"),
"client_id": env("CLIENT_ID"),
"auth_uri": env("AUTH_URI"),
"token_uri": env("TOKEN_URI"),
"auth_provider_x509_cert_url": env("AUTH_PROVIDER_X509_CERT_URL"),
"client_x509_cert_url": env("CLIENT_X509_CERT_URL")
}
# Create credentials from the service account info
credentials = service_account.Credentials.from_service_account_info(info=service_account_info)
# Initialize the Google Cloud Storage client with your credentials
client = storage.Client(credentials=credentials, project=env("PROJECT_ID"))
# List all buckets -> this works
buckets = list(client.list_buckets())
print("Buckets in {}:".format(client.project))
print(buckets)
except Exception as e:
print("Error initializing Google Cloud credentials: ", e)
#also settings.py
DEFAULT_FILE_STORAGE = 'fly_io_test.gcloud.GoogleCloudMediaFileStorage'
STATICFILES_STORAGE = "storages.backends.gcloud.GoogleCloudStorage"
GS_STATIC_BUCKET_NAME = env("DEV_STATIC_FILES_BUCKET_NAME")
GS_MEDIA_BUCKET_NAME = env("DEV_MEDIA_FILES_BUCKET_NAME")
STATIC_URL = f"https://storage.googleapis.com/{GS_STATIC_BUCKET_NAME}/admin/"
MEDIA_URL = f"https://storage.googleapis.com/{GS_MEDIA_BUCKET_NAME}/"
Я запустил gcloud auth login
, gcloud config set project <project_id>.
и затем gcloud auth application-default-login
в контейнере, кажется, успешно.
Я получаю ошибку АЦП
Я не знаю, будет ли это записывать медиафайлы в ведро MEDIA и файлы STATIC в статическое ведро.