jazzband / django-tinymce

TinyMCE integration for Django
http://django-tinymce.readthedocs.org/
MIT License
1.28k stars 317 forks source link

tinymce.min.js not loading with django-storages - due to missing parameters in URL #420

Closed agajdosi closed 10 months ago

agajdosi commented 1 year ago

I am using django-tinymce with django-storages set to S3 compatible DigitalOcean Spaces. All works well, scripts are collected and uploaded into S3 storage. However for some reason the {{ form.media }} is not rendering the URL for tinymce.min.js with missing space/bucket name in the URL:

<meta charset="utf-8">
<title>title</title>
<script src="https://fra1.digitaloceanspaces.com/static/tinymce/tinymce.min.js"></script>
<script src="https://fra1.digitaloceanspaces.com/diplomantky-space/static/django_tinymce/init_tinymce.js?AWSAccessKeyId=DO00FBYRKDHU443U2LDH&amp;Signature=VihAUT8AJOadxkHDDhITG5WUIb8%3D&amp;Expires=1673026550"></script>

I am not sure if the problem is on django-tinymce side, but as the init_tinymce.js loaded fine, I believe it could be - is it possible that resolution of URL for tinymce.min.js is wrong?

This issue seems a little bit similar to #401. Fix proposed in this issue fixes the problem for me, in app's settings.py I needed to set:

from django.contrib.staticfiles.storage import staticfiles_storage
    TINYMCE_JS_URL = staticfiles_storage.url('tinymce/tinymce.min.js')
claudep commented 1 year ago

The fix was reverted because it produced a regression. As the settings module may be called very early in the app start, it should not call staticfiles immediately, but rather lazily.

claudep commented 1 year ago

In the patch above, I suggested another approach so as accessing staticfiles_storage is delayed to after the initial import phase is over.