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?
if DEBUG:
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/"), )
else:
#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:
static
-admin
-static
ācss
āmain.css
ājs
-static-only
ācss
āmain.css
ājs
Hi,
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