Question

Note: this is different from django-staticfiles, in that it has compression built in.

My /static/ is used for static files I upload myself, while /media/ is used for files users upload. However, DJANGO_STATIC_MEDIA_URL relies on the fact that all static files are under one url.

Am I missing something? Or will I have to manually set {{ MEDIA_URL }} and {{ STATIC_URL }} on every template?

In addition, how do I set it up so that the symlinks generated by django-static are uploaded to S3 at all?

I am using Django 1.4, and my current config is:

DJANGO_STATIC = True
DJANGO_STATIC_MEDIA_URL = '//s3.amazonaws.com/%s/static/' % AWS_STORAGE_BUCKET_NAME
DJANGO_STATIC_MEDIA_ROOTS = [os.path.join(SITE_ROOT, 'static')]
Was it helpful?

Solution

Although I haven't used this app, after reading through the documentation it seems that DJANGO_STATIC_MEDIA_URL is a shortcut to minimize the need to include {{ MEDIA_URL }} when defining the location of your image src attribute.

You define DJANGO_STATIC_MEDIA_URL (www.mysite.com/media), then afterwards you can access the uploaded media's location like

<img src="{% staticfile "/foo.png" %}"/>

Rather than having to write the location as:

<img src="{{ MEDIA_URL }}{% staticfile "/foo.png" %}"/>

So, to reference your css and js static files, continue to use {{ STATIC_URL }}. To reference your uploaded media, either define DJANGO_STATIC_MEDIA_URL and use the {% staticfile %} templatetag only, or just use {{ MEDIA_URL }} as you normally would.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top