【发布时间】:2021-04-01 08:21:59
【问题描述】:
这是一个给我带来无数问题的错误,不幸的是,没有记录在案的解决方法。
我有一个在 Azure 上运行的 Django APP。我将本地更改推送到 Github,并通过 Github 操作将更改同步到 Azure。这一直进展顺利,构建/部署处理成功没有任何问题。
当我使用 django-storages[Azure] 在 Azure 上为媒体文件和静态文件创建存储帐户时,问题出现了。因此,每次我将更改从 localhost 推送到 Github 时,从 Github 到 Azure 的构建/部署过程都会运行并设法运行 collectstatic 命令,但不幸的是,由于未知错误而失败。在我的 Azure 门户上从 SSH 终端运行 collectstatic 会成功,尽管需要花费很长时间,所以,我假设是因为该过程花费了很长时间才最终失败。
我不需要每次更改站点时都运行此过程,因为我可以在需要时从 SSH 终端执行此操作。
我已阅读文档,其中大多数建议设置值 DISABLE_COLLECTSTATIC = 1 以禁用该过程。但是,我不知道该怎么做或在哪里设置值。我尝试在workflows file 上检查它,但没有类似的东西存在。这让我很困扰,因为我无法更新网站,因为我在本地进行的每项更改都因错误而无法部署。
这是我对 azure 存储帐户的设置:
# Media Storage Location
DEFAULT_FILE_STORAGE = 'custom_azure.AzureMediaStorage'
STATICFILES_STORAGE = 'custom_azure.AzureStaticStorage'
STATIC_LOCATION = "static"
MEDIA_LOCATION = "media"
AZURE_ACCOUNT_NAME = "my_storage_account"
AZURE_CUSTOM_DOMAIN = f'{AZURE_ACCOUNT_NAME}.blob.core.windows.net'
STATIC_URL = f'https://{AZURE_CUSTOM_DOMAIN}/{STATIC_LOCATION}/'
MEDIA_URL = f'https://{AZURE_CUSTOM_DOMAIN}/{MEDIA_LOCATION}/'
# CORS SETTINGS
CORS_ALLOW_ALL_ORIGINS = os.getenv('CORS_ALLOW_ALL_ORIGINS', True) == 'True'
CORS_ALLOWED_ORIGINS = [
"https://mywebsite.com",
]
这是自定义 Azure 文件:
import os
from storages.backends.azure_storage import AzureStorage
class AzureMediaStorage(AzureStorage):
account_name = os.environ['STORAGE_ACCOUNT_NAME'] # Must be replaced by your <storage_account_name>
account_key = os.environ['STORAGE_ACCOUNT_KEY'] # Must be replaced by your <storage_account_key>
azure_container = 'media'
file_overwrite = False
expiration_secs = None
class AzureStaticStorage(AzureStorage):
account_name = os.environ['STORAGE_ACCOUNT_NAME'] # Must be replaced by your storage_account_name
account_key = os.environ['STORAGE_ACCOUNT_KEY'] # Must be replaced by your <storage_account_key>
azure_container = 'static'
expiration_secs = None
这是我得到的 sn-p 或错误代码:
请帮助在部署期间禁用 collectstatic 功能。
【问题讨论】:
-
我试过这个,但不幸的是,它没有用。有具体放的地方吗?
标签: django azure github azure-storage