> ## Documentation Index
> Fetch the complete documentation index at: https://docs.preprod.world/llms.txt
> Use this file to discover all available pages before exploring further.

# 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.

<Warning>
  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.
</Warning>

Create a [CDN resource](/cdn/getting-started/create-a-cdn-resource/create-a-cdn-resource) before starting the integration. Configure its [custom domain](/cdn/cdn-resource-options/general/create-and-set-a-custom-domain-for-the-content-delivery-via-cdn) 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:

   ```bash theme={null}
   source env/bin/activate
   ```

2. From the directory that contains `manage.py`, collect static files into `STATIC_ROOT`:

   ```bash theme={null}
   python manage.py collectstatic
   ```

   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](https://docs.djangoproject.com/en/5.2/howto/static-files/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:

   ```text theme={null}
   https://origin.example.com/static/test.css
   https://origin.example.com/media/example.jpg
   ```

   Continue only after both origin URLs return the expected files.

5. In the [Gcore Customer Portal](https://portal.gcore.com), find the custom domain on the [CDN resources](https://portal.gcore.com/cdn/resources/list) page. Then set `STATIC_URL` and `MEDIA_URL` in `settings.py` to that domain:

   ```python theme={null}
   STATIC_URL = 'https://cdn.site.com/static/'
   MEDIA_URL = 'https://cdn.site.com/media/'
   ```

6. In templates, reference static files with the `{% static %}` template tag:

   ```html theme={null}
   {% load static %}
   <link rel="stylesheet" type="text/css" href="{% static 'test.css' %}">
   ```

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 <kbd>F12</kbd>), selecting the **Network** tab, and refreshing the page — static and media files should now load from the custom domain instead of the origin domain.
