Sfoglia il codice sorgente

if img_path start with '/', os.path.join is broken. so remove first '/'

if1live 8 anni fa
parent
commit
a9b16844c6
1 ha cambiato i file con 8 aggiunte e 0 eliminazioni
  1. 8 0
      better_figures_and_images/better_figures_and_images.py

+ 8 - 0
better_figures_and_images/better_figures_and_images.py

@@ -55,9 +55,17 @@ def content_object_init(instance):
                 # search src path list
                 # 1. Build the source image filename from PATH
                 # 2. Build the source image filename from STATIC_PATHS
+
+                # if img_path start with '/', remove it.
+                img_path = os.path.sep.join([el for el in img_path.split("/") if len(el) > 0])
+
+                # style: {filename}/static/foo/bar.png
                 src = os.path.join(instance.settings['PATH'], img_path, img_filename)
                 src_candidates = [src]
+
+                # style: {filename}../static/foo/bar.png
                 src_candidates += [os.path.join(instance.settings['PATH'], static_path, img_path, img_filename) for static_path in instance.settings['STATIC_PATHS']]
+
                 src_candidates = [f for f in src_candidates if path.isfile(f) and access(f, R_OK)]
 
                 if not src_candidates: