diff --git a/README.markdown b/README.markdown index 9cf2f8f..222d622 100644 --- a/README.markdown +++ b/README.markdown @@ -52,7 +52,7 @@ Add to INSTALLED_APPS: Additionally, replace the existing __MEDIA\_URL__ setting with: MEDIA_URL = '/media/' - + __MEDIA\_URL__ is the URL that will be used in debug mode. Otherwise, the __MEDIA\_URL__ will be inferred from the settings listed below. The following settings must also be added: @@ -82,6 +82,10 @@ Previous versions of mediasync rewrote URLs in CSS files to use the correct __ME MEDIASYNC_REWRITE_CSS = True +The media URL is selected based on the __DEBUG__ attribute in settings.py. When *True*, media will be served locally instead of from S3. Sometimes it is necessary to serve media from S3 even when __DEBUG__ is *True*. To force remote serving of media, set __MEDIASYNC\_SERVE\_REMOTE__ to *True*. + + MEDIASYNC_SERVE_REMOTE = True + ### urls.py A static media URL needs to be setup in urls.py that enables access to the media directory ONLY IN DEBUG MODE. @@ -169,4 +173,4 @@ When pushed to S3, the local URL is rewritten as the MEDIA\_URL from settings.py ## Running MEDIASYNC - ./manage.py mediasync \ No newline at end of file + ./manage.py syncmedia \ No newline at end of file diff --git a/mediasync/templatetags/media.py b/mediasync/templatetags/media.py index 392ee61..1bebd25 100644 --- a/mediasync/templatetags/media.py +++ b/mediasync/templatetags/media.py @@ -10,15 +10,16 @@ register = template.Library() assert hasattr(settings, "MEDIASYNC_AWS_BUCKET") +SERVE_REMOTE = getattr(settings, "MEDIASYNC_SERVE_REMOTE", not settings.DEBUG) BUCKET_CNAME = getattr(settings, "MEDIASYNC_BUCKET_CNAME", False) AWS_PREFIX = getattr(settings, "MEDIASYNC_AWS_PREFIX", None) -if settings.DEBUG: - mu = settings.MEDIA_URL -else: +if SERVE_REMOTE: mu = (BUCKET_CNAME and "http://%s" or "http://%s.s3.amazonaws.com") % settings.MEDIASYNC_AWS_BUCKET if AWS_PREFIX: mu = "%s/%s" % (mu, AWS_PREFIX) +else: + mu = settings.MEDIA_URL MEDIA_URL = mu.rstrip('/')