How come this Django plugin won't work?

北城余情 提交于 2019-12-12 04:00:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!