Django /static/ files not found, 404 error

Viewed 43

I have a problem with loading static files. It wont load images on my page at all. When i look for the address it says /apps/assets/img..... But it should be /static/assets/img like on the home page and login page. (/apps/ is my view name but i don't get it why it loads it like that..( All apps are in my installed apps directory, DIRS in templates is configured, i have 'django.contrib.staticfiles', tried running collectstatic, rerunning the server,

ALLOWED_HOSTS = ["*"] ,
STATIC_URL = '/static/' ,
STATIC_ROOT = os.path.join(VENV_PATH, 'static_root'
2 Answers

Steps to handle static files in Django:

  1. Create a (static) folder in the Root Directory of the Project
  2. Paste Your Static Files Folder in (static(js,CSS,images...etc)
  3. Now Do Setting in setting.py
STATIC_URL = '/static/'

STATICFILES_DIRS = [
    os.path.join(BASE_DIR,'static') 
]
  1. add {% load static %} tag on top of html page
  2. Now use {% static 'assets/image.jpg' %} tag in HTML File for calling static files
  3. Done

Set DEBUG value to True in settings.py. Remember that DEBUG value should be almost ALWAYS set to False in production, so read about overriding settings via additional file (settings_local.py and et cetera).

Related