0

I am trying to add a css file to my Django app, eventually in production but right now I can't even get it to run the local server using runserver. Whenever I load the page that should use the css file, I get the error "GET /static/ldap/style.css HTTP/1.1" 404 1666, with some variation on the filepath and error code, as I have tried a whole lot of combinations. Some other errors that I have gotten are

"GET /static/style.css HTTP/1.1" 404 1651 

Not Found: /ldap/style.css
[12/Jun/2018 15:07:07] "GET /ldap/style.css HTTP/1.1" 404 2804

My current setup is attempting to copy the official docs from the tutorial and the suggested doc in the settings.py file. I have:

in my settings.py:

STATIC_URL = '/static/' ,

in my search.html:

{% load static %}
<link rel="stylesheet" type="text/css" href="{% static 'ldap/style.css' %}">

And the file structure of my project root folder is thus (I am trying to implement this in the ldap application, to be clear):

├── conf
├── db.sqlite3
├── djangoWrapper
│   ├── __init__.py
│   ├── __pycache__
│   ├── settings.py
│   ├── templates
│   │   └── djangoWrapper
│   │       └── index.html
│   ├── urls.py
│   ├── views.py
│   └── wsgi.py
├── ldap
│   ├── admin.py
│   ├── apps.py
│   ├── forms.py
│   ├── __init__.py
│   ├── migrations
│   ├── models.py
│   ├── static
│   │   └── ldap
│   │       └── style.css
│   ├── templates
│   │   └── ldap
│   │       ├── apiOffline.html
│   │       ├── index.html
│   │       ├── results.html
│   │       └── search.html
│   ├── tests.py
│   ├── urls.py
│   └── views.py
├── manage.py
├── openshift
├── README.md
├── requirements.txt
├── runserver.sh
└── static
    └── admin

Are there any good ideas about what might be the problem here? I have tried following a lot of other related posts (like this) but none of them have worked, which might be related to the fact that none of them had the same error code (404 1666 and 404 1651) that I am having. I can give more information upon request, any help is appreciated. Thank you.

  • Side note: What did you use to make your project layout markup like that? – dfundako Jun 12 '18 at 21:19
  • I used the cl tool "tree." I don't know it very well and thus had to do some manual editing of it, but it seems pretty well fleshed out with arguments to do some pretty good stuff – turtlemcnuggets Jun 13 '18 at 12:47

2 Answers2

0

From first look, to me it looks like you may need to write your static directory as well, not just the static url path.

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

If you already have this in your project settings, let me know and I'll dive deeper into why it's only returning your file path as /ldap/style.css and edit my answer accordingly.

0

Try: python manage.py findstatic --verbosity 2 ldap/style.css to see where Django is looking for your static files.

sP_
  • 1,738
  • 2
  • 15
  • 29
  • it was only looking in the whole project static directory (projectFolder/static), not projectFolder/ldap/static. I copied the folder into the whole project directory and it worked, but this isn't supposed to be how it is, right? – turtlemcnuggets Jun 13 '18 at 13:05