Skip to content

Commit 98f01ea

Browse files
committed
Support manifest staticfiles storage.
Find the hashed name of the file from the staticfiles_storage class.
1 parent 1cb8d58 commit 98f01ea

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

react_render/django/render.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import logging
5+
from django.contrib.staticfiles.storage import staticfiles_storage, HashedFilesMixin
56
from django.contrib.staticfiles.finders import find as find_static
67
from django.core.serializers.json import DjangoJSONEncoder
78
from django.utils.safestring import mark_safe
@@ -36,6 +37,15 @@ def render_props(self):
3637

3738
def render_component(path_to_source, props=None, to_static_markup=False, json_encoder=None):
3839
if not os.path.isabs(path_to_source):
40+
# If its using the manifest staticfiles storage, to the hashed name.
41+
# eg. js/hello.js -> js/hello.d0bf07ff5f07.js
42+
if isinstance(staticfiles_storage, HashedFilesMixin):
43+
try:
44+
path_to_source = staticfiles_storage.stored_name(path_to_source)
45+
except ValueError:
46+
# Couldn't find it.
47+
pass
48+
# Now resolve it to the absolute path using the finders
3949
path_to_source = find_static(path_to_source) or path_to_source
4050

4151
if json_encoder is None:

0 commit comments

Comments
 (0)