I am currently working on setting up a global CSS file for my project, and although it seems to be correctly referenced in the location, the file itself cannot be found.
The relevant part of my settings.py file looks like this:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_ROOT = os.path.join(BASE_DIR, 'abcdefg')
STATIC_URL = '/static/'
STATICFILES_DIR = [
os.path.join(BASE_DIR, 'static')
]
Additionally, I have django.contrib.staticfiles
included in my installed apps list.
This is the current structure of my files:
Project/
├── abcdefg/
│ ├── admin/
│ ├── App/
├── Project/
│ ├── __init__.py
│ ├── settings/
│ ├── urls.py
│ └── wsgi.py
├── App/
│ └── static
│ └── App
│ └── css
│ └── test.css
│ └── __init__.py
│ └── admin.py
│ └── apps.py
│ └── models.py
│ └── views.py
│
├── manage.py
│
├── static/
│ └── base
| └── css
| └── test.css
└── templates/
└── base.html
The current content of my base.html file is as follows:
{% load static %}
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8>
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="{% static 'base/css/global.css' %}">
<title>Title {% block title %}{% endblock %}</title>
</head>
<body>
{% block content %}
<h1>Test</h1>
{% endblock %}
</body>
</html>
Every time I try to access the page, I receive an error message stating:
[08/Feb/2020 11:26:50] "GET /static/base/css/test.css HTTP/1.1" 404 1683
This error indicates that the link is correct, but the actual file is not being retrieved. Interestingly, changing the link href in base.html to {% static 'App/css/test.css %}
resolves the issue.
I've attempted to rectify by specifying a location mapped to STATIC_ROOT and running python manage.py collectstatic without success.
It feels like I might be missing something simple, so I went through the documentation and followed a video tutorial meticulously (you can watch it here), yet I'm still unable to import the global file successfully.
All relevant files have been uploaded to GitHub at https://github.com/JVP3122/django_help, just to provide a comprehensive overview. Also, note that this repository is not the official project repo, hence the visibility of Django secret key does not pose a security risk.