def replace_relative_media_urls(text):
if not settings.MEDIA_URL.startswith('/'):
# Replace only if MEDIA_URL is relative
return text
# Find every occurrence of the MEDIA_URL that is either following a
# whitespace, an equal sign or a quotation mark.
pattern = re.compile(r'([\s="\'])(%s)' % re.escape(settings.MEDIA_URL))
text = re.sub(pattern, r'\1%s\2' % settings.BASE_URL, text)
return text
评论列表
文章目录