1đź‘Ť
Instead of changing your directory structure, it would be better to just change the BASE_DIR to reflect the extra level you have introduced:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
With that small change you can keep your static folder in the “right” place.
0đź‘Ť
I’ve edited my settings (base.py) and I’ve moved my static folder.
Both the top level folder and the app have the same name, so I was getting which folder to put it in mixed up.
I now have:
top-folder
|-> project-folder (same name as top-folder)
|-> static
|-> app-folder
Rather than:
top-folder
|-> app-folder (same name as top-folder)
|-> project-folder (same name as top-folder)
|-> static
My basy.py snippit now looks like:
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates'),
os.path.join(BASE_DIR, 'gantt_charts/templates/gantt_charts')]
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'),
]
See how I’ve nestled a os.path.abspath
in there? That’s the other important step I think.
Also worth noting that you can add debugging print-outs to your settings (it’s Python code after all) which really helped. For instance:
print ("Base Dir is at:",BASE_DIR)
print ("Static Dir is at:",STATICFILES_DIRS)
And this runs each time the runserver command triggers.
- [Answer]-Django staticfiles_urlpatterns not working
- [Answer]-Django recursive menu
- [Answer]-Django – counting objects in database inside model declaraton