-1

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'
  • Could you add your url files ? After running collectstatic, have you something in the configured dir ? Your variable STATIC_ROOT is ok ? What is the VENV_PATH ? Have you set the STATICFILES_FINDERS variable ? – Lucas Grugru Sep 15 '22 at 07:29
  • Show your template with static file references and urls.py. Also it might help if you show folder structure and `collectstatic` output. – Ivan Starostin Sep 15 '22 at 08:24

2 Answers2

1

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
Ivan Starostin
  • 8,798
  • 5
  • 21
  • 39
-1

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).

Patryk Szczepański
  • 731
  • 1
  • 4
  • 12