问题
https://github.com/sunlightlabs/django-mediasync/
The media syncs to S3, but it doesn't change the {% MEDIA_URL %} to the s3 url in my template (when I go to production)
I followed all the instructions. Here's my settings.py.
MEDIASYNC = {
'AWS_KEY': AWS_ACCESSKEY,
'AWS_SECRET': AWS_SECRETKEY,
'AWS_BUCKET': "happy_media",
'BACKEND': 'mediasync.backends.s3',
'SERVE_REMOTE': True,
'AWS_BUCKET_CNAME': True,
'DOCTYPE': 'html4',
'USE_SSL': False,
'CACHE_BUSTER': 1234,
}
I also added this to the urls.py
from django.template import add_to_builtins
add_to_builtins('mediasync.templatetags.media')
I also have:
'django.core.context_processors.media' to my context processors in settings.py
回答1:
Try including 'django.core.context_processors.media' to your list of context processors in settings.py. I think that's what exposes MEDIA_URL and makes it visible in templates.
回答2:
Do you have this template contex processor ?
django.core.context_processors.request
回答3:
Solved.
I simply did this:
{% media_url %}
Notice that it's different from:
{{ MEDIA_URL }}
来源:https://stackoverflow.com/questions/4801139/how-come-this-django-plugin-wont-work