Skip to main content
Django CMS can deliver static files and uploaded media through a Gcore CDN resource by using the CDN domain in its asset URL settings.
Back up site files and the database before making changes. These steps assume standard Django STATIC_URL, STATIC_ROOT, MEDIA_URL, and MEDIA_ROOT settings without a custom storage backend or asset pipeline.
Create a CDN resource before starting the integration. Configure its custom domain with a valid CNAME record and an active SSL certificate.
  1. If the project uses a virtual environment, activate it with the command appropriate to the environment. For an environment named env on Linux or macOS, run:
  2. From the directory that contains manage.py, collect static files into STATIC_ROOT:
    The command copies static files into STATIC_ROOT; it doesn’t publish that directory or process uploaded media.
  3. Configure the origin web server or storage service to expose both Django asset directories:
    • Serve STATIC_ROOT under /static/.
    • Serve MEDIA_ROOT under /media/.
    The Django deployment process requires a web server or storage service to serve the collected static directory. Uploaded media remains separate from collectstatic and must be available from MEDIA_ROOT.
  4. 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.
  5. In the Gcore Customer Portal, find the custom domain on the CDN resources page. Then set STATIC_URL and MEDIA_URL in settings.py to that domain:
  6. In templates, reference static files with the {% static %} template tag:
  7. Restart or redeploy the Django application with the method used in the production environment so that it reloads the updated settings.py.
  8. 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.