CSS not displaying on page

Hi All,

I am facing a problem that Django 3.0.7 were css does not display, and it give a 404 status when calling the css, but the path is appear correct. Im am new to django. I was following a tutorial to start off, How can i resolve this?

    MEDIA_URL = '/media/'
    STATIC_URL = os.path.join(os.path.dirname(BASE_DIR), "static_in_env", "static-only/")
    STATIC_ROOT  = os.path.join(BASE_DIR, 'static')
    MEDIA_URL = os.path.join(os.path.dirname(BASE_DIR), "static_in_env", "media/")
    STATICFILES_DIR = ( os.path.join(os.path.dirname(BASE_DIR), "static_in_env", "static/"), )
    #os.path.normpath(os.path.dirname(__file__)) #os.path.join(BASE_DIR, 'static')
    STATIC_ROOT  = os.path.join(BASE_DIR, 'static')
    STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),)

Here is the project structure:

Couple things -

  • When posting code, the code needs to be surrounded by backticks - `, not apostrophes ('). I’ve taken the liberty of fixing your original post for this.
  • I’m looking for the requests and responses from the console where you’re running runserver, not the information in your browser’s console. (Copy / paste as text and not as an image)
  • We need to see the contents of your static directory - again, post the text of a directory listing, not a screen image.

What is your current setting for DEBUG?

Hi Ken,

Thanks for your help

I have my DEBUG set to True

This is what display on the console:

GET /Users/alexalvarez/Documents/Flask_Project/HoneySite/static/static-only/css/main.css HTTP/1.1" 404 1891

For the structure:


I was able to resolve, my issue i had to change the project structure and the my settings file.

Your STATIC_URL should not include the full “real” path for the file.
It’s just the prefix that is added to the root url, so it should be something like ‘static/’

1 Like