2

So im building my own django site. Right now im stuck with loading the statics. im getting the following error in the console:

 GET http://localhost:8000/static/css/style.css 500 (Internal Server Error)

Im trying to load a css file using the static taggs:

{{ STATIC_URL }}

in my settings i've edited the following:

PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))

STATIC_ROOT = os.environ.get('STATIC_ROOT',os.path.join(PROJECT_ROOT,"static",))
STATIC_URL = '/static/'


STATICFILES_DIRS = (
os.path.join(PROJECT_ROOT, "static",),
)

also added the TEMPLATE_CONTEXT_PROCESSORS:

TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
)

added the following to urls.py so i can navigate to localhost:8000/static/

urlpatterns += patterns('',
(r'^static/(?P<path>.*)$',
'django.views.static.serve',
{'document_root': settings.STATIC_ROOT}),
)

I'm not sute what im doing wrong. The PROJECT_ROOT is directing to the root of the project. I'm also using that for my TEMPLATE_DIR, and that works fine.

Hopefully someone can enlighten me! I've been googling around, and looked at other questions, but as far as i can see, i did everything how i'm supposed to!

Thx in advance!!

Kevinvhengst
  • 1,672
  • 4
  • 27
  • 40

3 Answers3

1

You have STATIC_ROOT in STATICFILES_DIRS ! That's incorrect.

Not sure if your issue is related to that, but it definitively show a lack of understanding of django staticfiles management.

Maybe after reading this article you'll understand it fully and be able to set it up right.

And you don't need this with DEBUG=True:

urlpatterns += patterns('',
(r'^static/(?P<path>.*)$',
'django.views.static.serve',
{'document_root': settings.STATIC_ROOT}),
)
jpic
  • 32,891
  • 5
  • 112
  • 113
1

Well, I had the same problem, and then I saw this error message:

"Your STATICFILES_DIRS setting is not a tuple or list; " django.core.exceptions.ImproperlyConfigured: Your STATICFILES_DIRS setting is not a tuple or list; perhaps you forgot a trailing comma?"

So, I converted the result of

(os.path.join(BASE_DIR, 'static'))

To a list:

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

Hope this help somebody.

Ivan
  • 51
  • 9
-1
Change the your debug into DEBUG=False
catherine
  • 22,492
  • 12
  • 61
  • 85
  • Could you explain why i should change it to this? I've tried it out, still getting the error. – Kevinvhengst Mar 15 '13 at 09:10
  • @KevinvanHengst Wait is your DEBUG = True? – catherine Mar 15 '13 at 09:15
  • 1
    Change that to DEBUG=False – catherine Mar 15 '13 at 09:31
  • Ok, when i changed it to False it works! But what does picking up the css file have to do with the DEBUB being True/False? – Kevinvhengst Mar 15 '13 at 09:43
  • When you set the debug into True (local). The system will check if you have 404.html. If it did not exist you will get 500 error – catherine Mar 15 '13 at 10:00
  • 3
    The problem was not the DEBUG. I went to the terminal and came across this: `"ImproperlyConfigured: The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting"` So i cleared my STATIC_ROOT and it works fine now. with DEBUG = True/False – Kevinvhengst Mar 15 '13 at 10:11