-
If the project uses a virtual environment, activate it with the command appropriate to the environment. For an environment named
envon Linux or macOS, run: -
From the directory that contains
manage.py, collect static files intoSTATIC_ROOT:The command copies static files intoSTATIC_ROOT; it doesn’t publish that directory or process uploaded media. -
Configure the origin web server or storage service to expose both Django asset directories:
- Serve
STATIC_ROOTunder/static/. - Serve
MEDIA_ROOTunder/media/.
collectstaticand must be available fromMEDIA_ROOT. - Serve
-
Before changing the public asset URLs, request a known static file and uploaded media file directly from the origin. Use the origin protocol and hostname configured for the CDN resource:
Continue only after both origin URLs return the expected files.
-
In the Gcore Customer Portal, find the custom domain on the CDN resources page. Then set
STATIC_URLandMEDIA_URLinsettings.pyto that domain: -
In templates, reference static files with the
{% static %}template tag: -
Restart or redeploy the Django application with the method used in the production environment so that it reloads the updated
settings.py. - Confirm the integration by opening the browser’s developer tools (press F12), selecting the Network tab, and refreshing the page — static and media files should now load from the custom domain instead of the origin domain.
Integrate CDN with CMS and other platforms
Integrate a CDN resource with Django CMS
Django CMS can deliver static files and uploaded media through a Gcore CDN resource by using the CDN domain in its asset URL settings.
Create a CDN resource before starting the integration. Configure its custom domain with a valid CNAME record and an active SSL certificate.