0

It was working fine, but for some reason, I have to change the staticfiles code and from there problem occurs.

settings.py

STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'blackportfolio/static'),
]

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

Staticfiles are creating my all css files are getting copy in staticfiles, browser also getting the staticfiles name <link rel="stylesheet" href="/static/style.2f83ab2e5052.css">

But its not searching them in static_root(staticfiles) it still searching them in static python manage.py findstatic --verbosity 2 styles.css but it returns with C:\Users\HP\Desktop\vir1\blackportfolio\blackportfolio/static C:\Users\HP\Desktop\vir1\venv\lib\site-packages\django\contrib\admin\static

the command I type.

manage.py collectstatic --clear
manage.py runserver --insecure.

project structure.

C:.
├───blackportfolio
│   ├───static
│   │   ├───admin
│   │   │   ├───css
│   │   │   │   └───vendor
│   │   │   │       └───select2
│   │   │   ├───fonts
│   │   │   ├───img
│   │   │   │   └───gis
│   │   │   └───js
│   │   │       ├───admin
│   │   │       └───vendor
│   │   │           ├───jquery
│   │   │           ├───select2
│   │   │           │   └───i18n
│   │   │           └───xregexp
│   │   └───images
│   └───__pycache__
├───portfolio
│   ├───migrations
│   │   └───__pycache__
│   └───__pycache__
├───staticfiles
│   ├───admin
│   │   ├───css
│   │   │   └───vendor
│   │   │       └───select2
│   │   ├───fonts
│   │   ├───img
│   │   │   └───gis
│   │   └───js
│   │       ├───admin
│   │       └───vendor
│   │           ├───jquery
│   │           ├───select2
│   │           │   └───i18n
│   │           └───xregexp
│   └───images
└───templates
Arsh Ergon
  • 160
  • 2
  • 15

1 Answers1

0

Please be more specific. You did not mention "prod" in your question at all. Note, browser and findstatic have nothing in common. findstatic collects files from STATICFILES_DIRS (not only) into STATIC_ROOT. "Browser" refers static files via STATIC_URL (hrefs in rendered HTML are generated based on this option).

When DEBUG=true - Django does the mapping job and maps URLs starting with STATIC_URL to STATIC_ROOT folder. On prod, when DEBUG=false, Django does not do this job - webserver has to do this.

So configure your Nginx (or other web server) to something like

location /static/ /* STATIC_URL */
{
    alias C:\Users\HP\Desktop\vir1\blackportfolio\staticfiles; /* STATIC_ROOT */
}

Deploying static files on prod is mentioned in the docs and has been discussed many times on SO.

Ivan Starostin
  • 8,798
  • 5
  • 21
  • 39
  • ```STATICFILES_DIRS``` files are copying to ```STATIC_ROOT``` but it still searching staticfiles in static folder, in production it fails. – Arsh Ergon Mar 03 '20 at 03:36