jmrivas86 / django-json-widget

An alternative widget that makes it easy to edit the new Django's field JSONField (PostgreSQL specific model fields)
MIT License
433 stars 88 forks source link

Adjust assets management to work with CDN tools like django-storages #22

Closed jeffjen closed 4 years ago

jeffjen commented 5 years ago

Adjust assets management to work with CDN tools like django-storage

  1. python manage.py collectstatic will upload content to with prefix json_widget
  2. CSS and JS references CDN full name and path
toracle commented 5 years ago

I had similar problem and inspected into it but found a little simpler solution than yours.

css and js property of Media class is rendered by render_js and render_css method.

When look into that method, it calls absolute_path method to make a path absolute, and absolute_path calls static function, and it calls StaticNode.handle_simple method.

And, this handle_simple method do the same things you do, turn a path to absolute one with storage.url().

So, default django Media logic act like this:

  1. If js or css path is an absolute path, use itself.
  2. If they are relative one,
    1. If django.contrib.staticfiles app is installed, get a staticfile_storage which is defined by settings.STATICFILES_STORAGE value, and use storage.url(path) to convert it to absolute.
    2. If the app is not installed, just add STATIC_URL prefix to the path.

So, I think a simple solution here is that, just to remove any URL prefix and using a relative path.

jmrivas86 commented 4 years ago

I close this PR because is solved in #30