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?

Community
  • 1
  • 1
Avi
  • 410
  • 3
  • 14
  • Do you actually have the file in your `static` folder? – Selcuk Apr 07 '16 at 03: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.. – Avi Apr 07 '16 at 04: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, )` – Manish Gupta Apr 07 '16 at 05:24
  • and on top use `{% load staticfiles %}`. Import static files like `"{% static "test.css" %}"` – Manish Gupta Apr 07 '16 at 05: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 – Avi Apr 08 '16 at 06:13
  • can you post urls.py? But i dont think it's a problem in urls.py since you can access the link and corresponding view. It must be something in tags you are using. – Manish Gupta Apr 08 '16 at 06:15

1 Answers1

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.

Leonard2
  • 894
  • 8
  • 21
  • I want to deploy. Debug = False definitely works but you can't use that for production. I have been through docs. – Avi Apr 08 '16 at 02:23