I located my client project folder and django project folder under the root folder separately. I configured django settings.py to contain client's app folder to serve in development and dist folder to be gathered by collectstatic
STATICFILES_DIRS = [os.path.join(BASE_DIR, "..", "Client/app"), # in development
os.path.join(BASE_DIR, "..", "Client/dist"), # to be gathered by collectstatic
collectstatic -i app
collectstatic -i Client/app
collectstatic -i ../Client/app
collectstatic -i app*
You would not do that normally. You would define a different
STATICFILES_DIR depending on what environment you run.
Very basic idea:
if DEBUG: STATICFILES_DIRS = [os.path.join(BASE_DIR, "..", "Client/app")] else: STATICFILES_DIRS = [os.path.join(BASE_DIR, "..", "Client/dist")]
Instead of relying on the
DEBUG setting though, I'd recommend you use a separate config file for each. You then choose which to run when you invoke Django.
For instance, assuming this file tree:
settings/ ├ __init__.py # empty ├ dev.py └ prod.py
…you'd start Django this way:
export DJANGO_SETTINGS_MODULE="settings.dev" ./manage.py runserver
To avoid repeating shared configuration, create a
common.py and import it from both
from settings.common import * (probably the only use case where it's permissible to import *).
Though it does not technically answer your question, I think this is a cleaner approach to the wider problem of handling environment-specific configuration.