DzITC
DzITC

Reputation: 879

Django: Static files are not found

I'm trying to add some static files to my project. I have tried adding a static folder to my app.

I have two apps:

  1. Authentication (authn),
  2. Main (main).

I have a lot of CSS/js content and I don't really know which is the best method to save the files, maybe all static files should be in one directory 'staticfiles' or each app should have 'static' folder. I have tried adding static folder to one of my apps, at this time - authn. And by trying to load the static files I firstly did python manage.py collectstatic, that put my all files into one folder, but I got two different folders now - admin, main. After tried putting all my static files into a static folder in authn app, but the static files were not loading after that. Here are my project structure and some photos and logs of the console, pycharm. enter image description here

enter image description here enter image description here

Upvotes: 0

Views: 606

Answers (2)

arnab das
arnab das

Reputation: 135

  1. make static folder outside the app
  2. inside static create two folder main and auth
  3. inside main and auth create css js img and another catagories of folder
  4. Put each app's static file into their folder.That is put main app's css into static/main/css/main.css like that

  5. In settings.py make some changes-

     BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    STATIC_URL = '/static/'
    

STATICFILES_DIRS = [ os.path.join(BASE_DIR, "static"), ]

Upvotes: 1

Rin Nguyen
Rin Nguyen

Reputation: 455

You need to add authn's static to STATICFILES_DIRS. Detail

STATICFILES_DIRS=[
  os.path.join(PROJECT_PATH, 'static'),
  os.path.join(PROJECT_PATH, 'authn', 'static')
]

Upvotes: 1

Related Questions