Pergunta

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?

Foi útil?

Solução

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
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top