python - Django - 媒体文件在生产中进行 404(Azure 存储)
问题描述
在将应用程序部署到 azure 应用服务器时,对于媒体文件,我指的是 azure blob 存储。我正在使用https://django-storages.readthedocs.io/en/latest/backends/azure.html文档。
我已经在我的settings.py文件中编写了这些代码行。
DEFAULT_FILE_STORAGE = 'index.custom_azure.AzureMediaStorage'
STATICFILES_STORAGE = 'index.custom_azure.AzureStaticStorage'
STATIC_URL = f'https://{AZURE_CUSTOM_DOMAIN}/{STATIC_LOCATION}/'
MEDIA_URL = f'https://{AZURE_CUSTOM_DOMAIN}/{MEDIAFILES_LOCATION}/'
在 custom_azure.py 文件中,我包含了我的类
从 storages.backends.azure_storage 导入 AzureStorage
class AzureMediaStorage(AzureStorage):
account_name = 'ACCOUNT_NAME' # Must be replaced by your <storage_account_name>
account_key = 'KEY' # Must be replaced by your <storage_account_key>
azure_container = 'media'
expiration_secs = None
location = 'media'
file_overwrite = False
class AzureStaticStorage(AzureStorage):
account_name = 'MY_STORAGE' # Must be replaced by your storage_account_name
account_key = 'My_KEY' # Must be replaced by your <storage_account_key>
azure_container = 'static'
expiration_secs = None
我的 urls.py 文件是这样的。
urlpatterns = [
path('',include('index.urls')),
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
我正在尝试引用 <http//domain.com/media/abc.png> 但不幸的是,它正在进行 404。
任何帮助表示赞赏!
解决方案
推荐阅读
- python - 在 Python 中使用 NLTK 对单词进行标记的问题。返回单个字母而不是单词的列表
- angular - 如何知道 takeWhile 何时停止?
- oracle - 数据库笔记 Oracle db
- php - Laravel 7 单元测试到注册路由重定向到主页
- r - 如何在ggplot中保留顶部和底部轴,同时删除面板边框
- c - 处理包含不同长度的二进制数据
- apache - 在 xampp 中启动 apache 服务器时出错
- json - MongoDB,将对象数组更改为包含其 ObjectId 的字符串数组
- java - 添加 NDK { abiFilters 'armeabi-v7a','arm64-v8a','x86','x86_64' } 后,Android 应用程序不兼容 64 位
- r - 是否可以为 R 文档中的图形添加标题?