code: def link_callback(uri, rel):
      
      # use short variable names
      sUrl = settings.STATIC_URL      # Typically /static/
      sRoot = settings.STATIC_ROOT    # Typically /home/userX/project_static/
      mUrl = settings.MEDIA_URL       # Typically /static/media/
      # Typically /home/userX/project_static/media/
      mRoot = settings.MEDIA_ROOT
  
      # convert URIs to absolute system paths
      if uri.startswith(mUrl):
          path = os.path.join(mRoot, uri.replace(mUrl, ""))
      elif uri.startswith(sUrl):
          path = os.path.join(sRoot, uri.replace(sUrl, ""))
      else:
          return uri  # handle absolute uri (ie: http://some.tld/foo.png)
  
      # make sure that file exists
      if not os.path.isfile(path):
          raise Exception(
              'media URI must start with %s or %s' % (sUrl, mUrl)
          )
      return path
docs: Convert HTML URIs to absolute system paths so xhtml2pdf can access those
      resources