1

I know this has been asked hundreds of times over the years here, here, here (and others) but I can't load my css files from my static folder.

  • Django 1.7
  • Python 2.7

My command line says

[07/Apr/2016 10:56:13] "GET / HTTP/1.1" 200 3596
[07/Apr/2016 10:56:13] "GET /static/compile/css/fbparse.min.6d40ca4cc832.css HTTP/1.1" 200 64
[07/Apr/2016 10:56:13] "GET /static/compile/js/fbparse.min.b40ef3f82f3a.js HTTP/1.1" 200 64

However, my log file says

2016-04-07 10:45:14,333 [WARNING] django.request: Not Found: /static/compile/css/fbparse.min.6d40ca4cc832.css
2016-04-07 10:56:13,848 [WARNING] django.request: Not Found: /static/compile/css/fbparse.min.6d40ca4cc832.css
2016-04-07 10:56:13,852 [WARNING] django.request: Not Found: /static/compile/js/fbparse.min.b40ef3f82f3a.js

And of course, the site does not load the css file.

When I try

http://127.0.0.1:8000/static/compile/css/fbparse.min.6d40ca4cc832.css

It gives me error 404

Here is what I have in settings file

import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
rel = lambda *x: os.path.join(BASE_DIR, *x)

DEBUG = False

MEDIA_ROOT = rel('public', 'media')
MEDIA_URL = '/media/'
STATIC_ROOT = rel('public', 'static')
STATIC_URL = '/static/'


STATICFILES_DIRS = (
    rel('static_src'),
)

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

.....
)

Here is what I have in the Base html

<!DOCTYPE html>
{% load pipeline static i18n stats_tags %}
<html>
<head>
    <meta charset=utf-8 />

    <title>My site title</title>

    {% stylesheet 'global' %}

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    {% javascript 'global' %}
    {% if debug %}
        <script src="{% static "components/less.js/dist/less.min.js" %}"></script>
        {% if LESS_DEBUG %}
            <script type="text/javascript">
                less.env = "development";
                less.watch();
            </script>
        {% endif %}
    {% endif %}

</head>

I have tried putting the static folder in the root directory, inside public, inside static_src but nothing seems to work.

Can anyone tell me what I am doing wrong?

6
  • Do you actually have the file in your static folder? Commented Apr 7, 2016 at 3:15
  • Yes. I have checked many times to make sure I have that. Also checked if the contents are correct - file names are correct etc. All is there.. Commented Apr 7, 2016 at 4:08
  • for you static file settings.. try these STATIC_PATH = os.path.join(BASE_DIR,'static') STATIC_URL = '/static/' # You may find this is already defined as such. STATICFILES_DIRS = ( STATIC_PATH, ) Commented Apr 7, 2016 at 5:24
  • and on top use {% load staticfiles %}. Import static files like "{% static "test.css" %}" Commented Apr 7, 2016 at 5:25
  • @ManishGupta tried all that you suggested. Did not work. Based on the http error code, it seems like it might be URL.py issue but still does not get solved Commented Apr 8, 2016 at 6:13

1 Answer 1

0

Did you use manage.py runserver?

In that case you want to use dev-server with DEBUG = False, you can simulate it via manage.py runserver --insecure.

If you want to deploy your django project with WAS like Apache, you need to serve your static files independently as stated in Docs.

Sign up to request clarification or add additional context in comments.

1 Comment

I want to deploy. Debug = False definitely works but you can't use that for production. I have been through docs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.