Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

121
Visualizações
Override the DEFAULT_FILE_STORAGE with MEDIA_URL to integrate Azure CDN

I'm using Azure Storage account for storing my media files

Setting it is simple in settings.py like this:

DEFAULT_FILE_STORAGE = 'storages.backends.azure_storage.AzureStorage'
AZURE_ACCOUNT_NAME = 'my_account_name'
AZURE_ACCOUNT_KEY = 'my_account_key'
AZURE_CONTAINER = 'my-container'

However, I considered later that I want to use Azure CDN instead for serving my media files. How will I point it to the CDN URL instead? I tried setting it in the MEDIA_URL like

MEDIA_ROOT = os.path.join(BASE_DIR, 'upload')
MEDIA_URL = '//my-media.azureedge.net/my-container/'

However my storage-account blob is the one being shown as default URL which is 'xxxxx.blob.core.windows.net' instead of my MEDIA URL..

How will I show the MEDIA_URL instead of 'xxxxx.blob.core.windows.net'?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Thankfully I already have an answer for this one. You need to override the storage backend class of Azure on the 'storages' library replacing the blob hostname with the CDN hostname.

settings.py

MEDIA_URL = '//my-media.azureedge.net/my-container/'

storages.py

import re
from jaguar import settings
from storages.backends.azure_storage import AzureStorage


class AzureCDNURL(AzureStorage):

    def url(self, name):
        ret = super(AzureCDNURL, self).url(name)
        _ret = re.sub('//[a-z.0-9A-Z]*/', settings.MEDIA_URL, ret)
        return _ret
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda