Correctly use the regex replacement function to substitute all urls in a particular chunk of text
This commit is contained in:
@@ -5,14 +5,14 @@ PREFIX = '/static/'
|
||||
STATIC_PATTERN = re.compile(r"""
|
||||
(?P<quote>['"]) # the opening quotes
|
||||
{prefix} # the prefix
|
||||
.*? # everything else in the url
|
||||
(?P<rest>.*?) # everything else in the url
|
||||
(?P=quote) # the first matching closing quote
|
||||
""".format(prefix=PREFIX), re.VERBOSE)
|
||||
PREFIX_LEN = len(PREFIX)
|
||||
|
||||
def replace(static_url):
|
||||
quote = static_url[0]
|
||||
url = staticfiles_storage.url(static_url[1+PREFIX_LEN:-1])
|
||||
quote = static_url.group('quote')
|
||||
url = staticfiles_storage.url(static_url.group('rest'))
|
||||
return "".join([quote, url, quote])
|
||||
|
||||
def replace_urls(text):
|
||||
|
||||
Reference in New Issue
Block a user