0

I have a static directory inside my apps folder. I added this line of code to my projects settings.py file

    STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
    '/var/www/static/',
]

The file continues to result in a 404 not found. I'm getting stuck, what should I do?

Dylan Cronkhite
  • 423
  • 1
  • 8
  • 15

1 Answers1

0

It probably isn't mistake in your static files settings. But to be sure the relevant settings for static folder in app directories is STATICFILES_FINDERS https://docs.djangoproject.com/en/2.1/ref/settings/#staticfiles-finders. But the AppDirectoriesFinder should be present by default so it is probably OK.

Your problem is probably in your URL scheme:

For development purposes make sure you have django.contrib.staticfiles in your installed apps, DEBUG = True and STATIC_URL = '/static/' (or something similar). Then you should be able access the files.

For deploying it is more complicated but essentially you have setup STATIC_ROOT, before starting the server run python manage.py collectstatic command which will copy all static files to one location and then setup your server (Nginx) to serve the files from this folder under /static/ URL. Here is the official documentation https://docs.djangoproject.com/en/2.1/howto/static-files/#deployment

Note: if your app is foo and you have bar file in your static directory under foo app the URL for the file will be /static/foo/bar.

Sgiath
  • 360
  • 2
  • 8
  • I think I missled you. The static file isnt inside a specific app's folder. It is inside the folder with the other apps. It is possible or should I leave my css files in one app and just reference the css from that app's static files? – Dylan Cronkhite Oct 28 '18 at 05:46
  • Oh then make sure you add `os.path.join(BASE_DIR, "apps", "static")` instead if it is in your apps folder (assuming `BASE_DIR` points at the root of the project). – Sgiath Oct 28 '18 at 05:48
  • This feels like the right answer, but it doesn't seem to be working. – Dylan Cronkhite Oct 28 '18 at 05:54
  • Did you setup and check everything as I wrote in the main answer? It is still relevant :) – Sgiath Oct 28 '18 at 05:56
  • lets go down the list: django.contrib.staticfiles is installed, STATIC_URL is /static/, I don't know what STATICFILES_FINDERS is though. – Dylan Cronkhite Oct 28 '18 at 05:59