A while ago, I attempted to use "collectstatic" in Django to serve my static files and failed miserably. Now I am finally trying to get my static files serving correctly in my development environment. I can't figure out what has gone wrong.
When I run python manage.py findstatic images/add.png
console returns:
base path: C:\Projects\AlmondKing\AlmondKing
static files dirs: C:\Projects\AlmondKing\AlmondKing\static
No matching file found for 'images/add.png'.
The directory paths are correct, but it still can't locate my files. I've tried a number of different settings configurations to no avail. Can anyone spot my problem? Here are what I think are all the relevant settings:
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
DEBUG = True
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'AlmondKing.InventoryLogs',
'AlmondKing.FinancialLogs',
'AlmondKing.AKGenius',
)
STATIC_URL = '/static/'
STATIC_FILES_DIRS = (
os.path.join((BASE_DIR), "static")
)
print("base path:", BASE_DIR)
print("static files dirs:", STATIC_FILES_DIRS)
EDIT: I found the findstatic --verbosity 2 command
and the only directory being searched is: C:\Users\Adam\Envs\AlmondKing\lib\site-packages\django\contrib\admin\static
Apparently it is only looking in my virtual environment, instead of my project directory. Is this normal Django behavior?
The setting is STATICFILES_DIRS
, not STATIC_FILES_DIRS
.
You are also missing a comma in the setting. Without the comma it is treated as a string not a tuple.
It should be:
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
At last! Referring here, I learned that the static files directory must be located within the directory of an individual app. I had the static directory in the project root. I moved it into an app directory and it is working now.
This whole project will be using these same static files. If someone knows, do I need to have a copy of them in every App's directory, or can all of my project's apps share a static directory? Thanks!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With