Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

116
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!