Closed Demo318 closed 1 year ago
Implemented a solutions in my settings.py
(similar to this):
#Tiny MCE fix
if config('CODE_ENVIRONMENT') == 'production':
from django.contrib.staticfiles.storage import staticfiles_storage
TINYMCE_JS_URL = staticfiles_storage.url('tinymce/tinymce.min.js')
TINYMCE_JS_ROOT = staticfiles_storage.url('tinymce')
Now tinymce.min.js
and tinymce/
are pulling from Google Cloud Storage like everything else:
<script src="https://storage.googleapis.com/final-sigma-website-resources/tinymce/tinymce.min.js?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=final-sigma-website%40final-sigma-website-357112.iam.gserviceaccount.com%2F20220725%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20220725T033134Z&a ... b79fd9"></script>
However, now where the editor should load in my admin page, there's just an empty space.
You may (re-)read https://docs.djangoproject.com/en/4.0/intro/tutorial06/ which shows how you should refer to static files in your templates with the static tag. However, including {{ form.media }}
in your form templates should even take care of including tinymce static files.
Thanks, @claudep, what about for django's built-in admin app where I'm not personally designing the templates?
The admin app calls {{ form.media }}
, so with the normal flow, the proper JS paths should be output without the need to do anything else. (Media.render_js
should call the static
template tag, which should call staticfiles_storage.url(path)
).
I think I found it.
The request to download tinymce/theme.min.js
goes to the right Google Cloud Storage bucket, but it does not include the authentication parameters.
Right now looks like this (and returns a 403 error):
Request URL: https://storage.googleapis.com/final-sigma-website-resources/tinymce/themes/silver/theme.min.js
When it should look like this (the init_tinymce.js
request that loads just fine):
Request URL: https://storage.googleapis.com/final-sigma-website-resources/django_tinymce/init_tinymce.js?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=final-sigma-website%40final-sigma-website-357112.iam.gserviceaccount.com%2F20220725%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20220725T123730Z&X-Goog-Expires=86400&X-Goog-SignedHeaders=host&X-Goog-Signature=4dbeb4944b654d1 ... b199ddfb6
I can do some digging to find where that url is defined, unless @claudep you know off-hand.
I guess this might be a django-storages
usage or bug issue. I'm not using this package so unfortunately cannot help much.
In development on my own machine, where
collectstatic
delivers all static files to a standardstaticfiles/
folder in my project directly, TinyMCE loads just fine when editing fields inlocalhost:8000/admin
interface.In production, I use
django-storages[google]
to host static & media files from Google Cloud. The above code is from the<head>
of my admin page in production. As you can see, all static-files urls are properly changed except TinyMCE.Django Storages for Google Cloud Storage
My Project