-1

I have a Django project structure like this

 Project
    app
    media
    static
      style.css 
    templates
      base.html

and in settings

    PROJECT_ROOT = os.path.join(os.path.dirname(__file__), '..') 
    SITE_ROOT = PROJECT_ROOT
    STATIC_ROOT = os.path.join(SITE_ROOT, 'static')

    STATIC_URL = '/static/'

    STATICFILES_DIRS = (
        os.path.join(SITE_ROOT,'static')
      )

     STATICFILES_FINDERS = (
        'django.contrib.staticfiles.finders.FileSystemFinder',
         'django.contrib.staticfiles.finders.AppDirectoriesFinder',
     )

and in base.html reference to the css file :

  <link href="{{STATIC_URL}}/style.css" rel="stylesheet" type="text/css" />

and it gives an error :

 "The STATICFILES_DIRS setting should "
 ImproperlyConfigured: The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting

the browser shows html files in no-css style , what can be the problem?

hln
  • 1,071
  • 4
  • 21
  • 37

1 Answers1

1

This line should be the culprit:

<link href="{{STATIC_URL}}/style.css" rel="stylesheet" type="text/css" />

Remove the trailing slash after {{STATIC_URL}}

You should say

<link href="{{STATIC_URL}}style.css" rel="stylesheet" type="text/css" />

Can you make sure STATICFILES_DIRS refer to your static directory.

from django.conf import settings
print settings.STATICFILES_DIRS
Akshar Raaj
  • 14,231
  • 7
  • 51
  • 45
  • it printsout something like 'C:\\Users\\hl\\workspace\\faahjaelp\\theproject\\..\\static' and show an error "The STATICFILES_DIRS setting should " ImproperlyConfigured: The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting – hln Apr 28 '13 at 14:24
  • If you are in development mode, you can comment your `STATIC_ROOT` for now and it should be fine. – Akshar Raaj Apr 28 '13 at 14:31
  • thanks it worked, but what if i have to put it in production? – hln Apr 28 '13 at 14:34
  • Put STATIC_ROOT = os.path.join(SITE_ROOT, 'static_root'). Its only used when you use `python manage.py collectstatic` and it only tells the location where all your static files should be collected to. So, its just telling to django that collect all my static files in directory named `static_root` – Akshar Raaj Apr 28 '13 at 14:36