Search code examples
pythondjangodjango-staticfiles

Django Can't Find a static file that's already there


I'm facing a very peculiar problem using Django. So basically I have a CSS static file inside <static/css> directory, and here's the strange message from terminal: "GET /home/.../django/mysite/static/css/style.css HTTP/1.1" 404 1932, while the file is actually there!

settings file:

DEBUG = True
ALLOWED_HOSTS = ['*']
STATIC_URL = str(BASE_DIR) + '/static/' 
STATIC_ROOT = str(BASE_DIR.joinpath('static'))
STATICFILES_DIR = (str(BASE_DIR.joinpath('static')),)

I have used the command "python manage.py collectstatic", but it didn't work; I also checked out this page: https://docs.djangoproject.com/en/4.2/howto/static-files/ but there was no solution for me... Please tell me what's wrong!


Solution

  • try making your STATIC_URL as follows

    STATIC_URL = 'static/'

    You are currently constructing it out of your project directory structure, but the web page needs it in a website context, eg, domain.com/static/