0

I do not know why Django created a folder named staticfiles rather than static as expected. That might be the reason why I got an error after running python manage.py collectstatic:

The system cannot find the path specified: 'D:...\\static'

My settings file included:

from pathlib import Path
import os
import django_heroku

BASE_DIR = Path(__file__).resolve().parent.parent

STATIC_URL = '/static/'
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

I had already tried to change 'staticfiles' to 'static' in STATIC_ROOT, but no success.

Could anyone please explain why and how to create a folder name "static"?

Thank you very much in advance!

Trung Nguyen
  • 37
  • 1
  • 6
  • In production (DEBUG=False), you should to create it by hand and execute `python manage.py collectstatic` – dani herrera Mar 23 '22 at 13:29
  • Try changing the url to `STATIC_URL = '/staticfiles/'`, and check out https://stackoverflow.com/a/37717024/10951070. I've had some issues with this because I had a static folder in my root project as well as each of my app folders. Oh, and keep the other two settings as you have them already in your question. – raphael Mar 23 '22 at 14:20
  • It is not working. – Trung Nguyen Mar 23 '22 at 14:23
  • Not sure why. Two ideas. One, use [findstatic](https://docs.djangoproject.com/en/4.0/ref/contrib/staticfiles/#findstatic), run `python manage.py findstatic [filename-of-a-static-file]` for a clue. Second edit your question with your project structure. – raphael Mar 23 '22 at 14:33

1 Answers1

0

I considered your static files are placed inside your app(s)

Try removing STATICFILES_DIRS so the setting will be:

STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR / 'staticfiles'

...and try to re-run python manage.py collectstatic

  • Here is how collectstatic works:
    • First it collect static files from STATICFILES_DIRS if any, if there is no STATICFILES_DIRS in settings it collects static files from each app
    • Then placed them to STATIC_ROOT, so if your static files are placed inside your app(s) better to remove STATICFILES_DIRS

If still there is an error share your project structure

Adil Mohak
  • 240
  • 2
  • 11