Open dmsimard opened 5 years ago
Link to relevant bit of code: https://github.com/evansd/whitenoise/blob/0e94fc16a6c47b78ec1fe818d087ce79914ff8f4/whitenoise/base.py#L101-L105
Unfortunately there's no completely clean way of dealing with this. Ideally we'd set STATIC_ROOT
to None as a way of signalling that we never intend to write anything to it and then WhiteNoise would ignore the setting. But Django throws an ImproperlyConfigured exception if you try to do that. So you have to set it to a filesystem path, and WhiteNoise then has no way of knowing that you intended the directory to be missing.
Probably the easiest thing to do is to silence the warning by adding something like the following to you settings file:
import warnings
warnings.filterwarnings("ignore", message="No directory at", module="whitenoise.base" )
@evansd that's not a bad idea. For the time being we had worked around it by making sure that STATIC_ROOT was created with something like:
if not os.path.isdir(STATIC_ROOT):
os.makedirs(STATIC_ROOT, mode=0o755)
Thanks for considering the issue -- if there's no obvious fix maybe we could document the workaround ?
My pytest
solution (just put it in your conftest.py
):
import pytest
@pytest.fixture(autouse=True)
def whitenoise_autorefresh(settings):
"""
Get rid of whitenoise "No directory at" warning, as it's not helpful when running tests.
Related:
- https://github.com/evansd/whitenoise/issues/215
- https://github.com/evansd/whitenoise/issues/191
- https://github.com/evansd/whitenoise/commit/4204494d44213f7a51229de8bc224cf6d84c01eb
"""
settings.WHITENOISE_AUTOREFRESH = True
When you want to practice on ur local server ,Set Debug=True, and run server again. Problem Solved And When you deploy into Heroku or any other pltfrm. Set Debug = False. This will Secure Ur Webpage ;)
This works for me
from django.test.utils import ignore_warnings ignore_warnings(message="No directory at", module="whitenoise.base").enable()
im currently having this same issue while deploying to railway.app
im currently having this same issue while deploying to railway.app
me too... oh God !!!
@ZamirSZN @diegobarbo We are three now...
@Ian2012 @diegobarbo did you guys get to fix it , i did by using the heroku build pack
I am getting the same issue while running unit test
Unfortunately there's no completely clean way of dealing with this. Ideally we'd set
STATIC_ROOT
to None as a way of signalling that we never intend to write anything to it and then WhiteNoise would ignore the setting. But Django throws an ImproperlyConfigured exception if you try to do that. So you have to set it to a filesystem path, and WhiteNoise then has no way of knowing that you intended the directory to be missing.Probably the easiest thing to do is to silence the warning by adding something like the following to you settings file:
import warnings warnings.filterwarnings("ignore", message="No directory at", module="whitenoise.base" )
Okay ... Getting this error on railway now ...
Thanks for developing whitenoise :+1:
I have a use case where I'd like whitenoise to transparently handle all the static files for a Django application. The amount of static files is minimal and gets little to no traffic.
Reproducing this particular issue should be fairly easy:
whitenoise.middleware.WhiteNoiseMiddleware
in the settings.pyMIDDLEWARE
listWHITENOISE_USE_FINDERS = True
in settings.pySTATIC_ROOT
to a path that doesn't exist yet (because Django creates this only when running collectstatic, which I'd actually like to avoid)Running
manage.py runserver
will raise a warning like this:The warning isn't a blocker: it doesn't prevent runserver or a wsgi server from starting. The warning might not be relevant when
WHITENOISE_USE_FINDERS
isTrue
, though.