Closed romanvm closed 6 years ago
@romanvm This fix unfortunately isn't completely working for me.
if JS_URL is None:
# Ugly hack that allows to run collectstatic command with ManifestStaticFilesStorage
_orig_debug = settings.DEBUG
if 'collectstatic' in sys.argv:
settings.DEBUG = True
JS_URL = staticfiles_storage.url('tinymce/js/tinymce/tinymce.min.js')
settings.DEBUG = _orig_debug
I have a bunch of other commands using production environment variables, but locally. For example, my script to refresh the database now fails:
#!/bin/sh
set -e
envdir envs/prod pipenv run django-admin pg_dump && \
envdir envs/local pipenv run django-admin dropdb --noinput # allow dropdb to fail locally
envdir envs/local pipenv run django-admin createdb --noinput && \
envdir envs/local pipenv run django-admin pg_restore && \
envdir envs/local pipenv run django-admin migrate # runs local migrations on top of last version of prod db
The envdir envs/prod pipenv run django-admin pg_dump
command fails.
Is this the same issue with ValueError
and ManifestStaticFilesStorage
?
@romanvm yeah, I get the ValueError since 'collectstatic' in sys.argv
doesn't apply. I'm running a different command so collectstatic
isn't in the sys.argv. Seems like the code gets run on import.
I suspected that it may not work with other management commands that import the whole Django project. Currently I don't have an acceptable solution so any help is appreciated.
Is there any specific reason why you are using ManifestStaticFilesStorage
. Maybe the default file storage class will be enough?
When
ManifestStaticFilesStorage
is used as a storage class for static files, runningany Django management command withcollectstatic
DEBUG = False
causesValueError
exception becausestaticfiles_storage.url()
tries to get hash-versioned filename frommanifest.json
that is not there yet. Current workaround is to temporarily switch toDEBUG = True
and runcollectstatic
but it is not a good idea to manipulate withDEBUG
in production. A solution is needed that both allows to runcollectstatic
withDEBUG = False
and retains serving hash-versioned static assets fromtinymce4-lite
.