question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Warning about Django's STATIC_ROOT directory not found when WHITENOISE_USE_FINDERS is true

See original GitHub issue

Thanks for developing whitenoise 👍

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.py MIDDLEWARE list
  • WHITENOISE_USE_FINDERS = True in settings.py
  • Set STATIC_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:

.tox/runserver/lib/python3.6/site-packages/whitenoise/base.py:104: UserWarning: No directory at: /var/www/static
  warnings.warn(u'No directory at: {}'.format(root))

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 is True, though.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

17reactions
paweladcommented, Nov 26, 2019

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
6reactions
evansdcommented, Mar 14, 2019

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" )
Read more comments on GitHub >

github_iconTop Results From Across the Web

Django - Static file not found - Stack Overflow
I'm trying to serve static files within my Django 1.3 development environment. Here are my settings ... STATIC_ROOT = '/home/glide/Documents/django/cbox/static/ ...
Read more >
Using WhiteNoise with Django
If your application is not running at the root of the domain and FORCE_SCRIPT_NAME is set then this value will be removed from...
Read more >
Static Files in Django - Dan's Cheat Sheets's documentation!
To get the static files to the directory where your web server will look for them, you'll set STATIC_ROOT to that directory path,...
Read more >
Warning about Django's STATIC_ROOT directory not found ...
Thanks for developing whitenoise :+1: I have a use case where I'd like whitenoise to transparently handle all the static files for a...
Read more >
How to manage static files (e.g. images, JavaScript, CSS)
Store your static files in a folder called static in your app. ... by runserver when DEBUG is set to True (see django.contrib.staticfiles.views.serve()...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found