Search code examples
pythondjangoapachestatic-files

ERR_ABORTED 404 - Django - Static Files


I get the following error in my web site:

https://www.mywebsite.com/project/static/js/stylish-portfolio.min.js net::ERR_ABORTED 404

I don't understand why, because all my static files are in chmod 775.

May be it's due to my setting file, but i don't see the issue. :/

My setting file:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
GPAAS_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

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

STATIC_URL = '/project/static/'
STATIC_ROOT = os.path.join(GPAAS_DIR, 'static')
MEDIA_ROOT = os.path.join(GPAAS_DIR, 'media')
MEDIA_URL = '/project/media/'

I use:

  • Apache 2.4.35
  • Python 3.6.5
  • Django 2.2.4

Has anyone ever had this issue, or may be some advice to solve this problem?

Could you help me please?

EDIT :

My project is like that :

.
└── DjangoMainFolder
    ├── DjangoApp
    │   ├── admin.py
    │   ├── __init__.py
    │   ├── migrations
    │   ├── static
    │   │   └── DjangoApp
    │   │       ├── custom.css
    │   │       └── custom.js
    │   ├── templates
    │   │   └── DjangoApp
    │   │       ├── base.html
    │   │       └── z_AND_SO_ON
    │   └── z_AND_SO_ON
    └── DjangoProjectFiles
    |    ├── settings.py
    |    ├── urls.py
    |    └── wsgi.py
    |__ static
         |__ img
         |__ js
         |__ css

I would like use the file static DjangoMainFolder/static/, not the static in my APP.


Solution

  • Do you have static files directive declared in INSTALLED_APPS?

    INSTALLED_APPS = [
        'django.contrib.staticfiles',
    ]
    

    Also, try STATIC_URL = '/static/' and don't forget to put as the first line inside your html: {% load staticfiles %}

    Later edit: {% load staticfiles %} is the correct syntax, when referring them inside the template you use {% static '/DjangoApp/FileName.extension' %} considering you use the following project structure:

    .
    └── DjangoMainFolder
        ├── DjangoApp
        │   ├── admin.py
        │   ├── __init__.py
        │   ├── migrations
        │   ├── static
        │   │   └── DjangoApp
        │   │       ├── custom.css
        │   │       └── custom.js
        │   ├── templates
        │   │   └── DjangoApp
        │   │       ├── base.html
        │   │       └── z_AND_SO_ON
        │   └── z_AND_SO_ON
        └── DjangoProjectFiles
            ├── settings.py
            ├── urls.py
            └── wsgi.py