Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Recently I deployed a Django powered application but I have some problem with static files. Sometimes (and only sometimes), I get 500 Internal Server Error in getting static files such as css/js/image. Please take look at this images:

First request:

enter image description here

Second:

Second request

and last request:

First request

You can see that in three separate requests, I got different result in static files.

Apache Log:

[Wed Oct 10 16:00:08 2012] [error] [client 37.98.23.93]   File "/usr/lib/python2.6/site-packages/django/utils/decorators.py", line 91, in _wrapped_view, referer: http://mydomain.biz/static/style/main.css
[Wed Oct 10 16:00:08 2012] [error] [client 37.98.23.93]     response = view_func(request, *args, **kwargs), referer: http://mydomain.biz/static/style/main.css
[Wed Oct 10 16:00:08 2012] [error] [client 37.98.23.93]   File "/usr/lib/python2.6/site-packages/django/views/defaults.py", line 32, in server_error, referer: http://mydomain.biz/static/style/main.css
[Wed Oct 10 16:00:08 2012] [error] [client 37.98.23.93]     t = loader.get_template(template_name) # You need to create a 500.html template., referer: http://mydomain.biz/static/style/main.css
[Wed Oct 10 16:00:08 2012] [error] [client 37.98.23.93]   File "/usr/lib/python2.6/site-packages/django/template/loader.py", line 145, in get_template, referer: http://mydomain.biz/static/style/main.css
[Wed Oct 10 16:00:08 2012] [error] [client 37.98.23.93]     template, origin = find_template(template_name), referer: http://mydomain.biz/static/style/main.css
[Wed Oct 10 16:00:08 2012] [error] [client 37.98.23.93]   File "/usr/lib/python2.6/site-packages/django/template/loader.py", line 138, in find_template, referer: http://mydomain.biz/static/style/main.css
[Wed Oct 10 16:00:08 2012] [error] [client 37.98.23.93]     raise TemplateDoesNotExist(name), referer: http://mydomain.biz/static/style/main.css
[Wed Oct 10 16:00:08 2012] [error] [client 37.98.23.93] TemplateDoesNotExist: 500.html, referer: http://mydomain.biz/static/style/main.css

I have Apache 2.* and Django 1.4.1 with Python 2.6 on CentOS 5.

share|improve this question

migrated from stackoverflow.com Oct 10 '12 at 22:47

This question came from our site for professional and enthusiast programmers.

1  
Is there anything in your apache logs that might give a little more indication? –  Timmy O'Mahony Oct 10 '12 at 21:09
    
Question updated. –  Afshin Mehrabani Oct 10 '12 at 21:17
1  
As it says in the logs, first you need to create a 500.html template. Once you've done that, you should be emailed a traceback with the real problem, if you have correctly set ADMINS in your settings. –  Alasdair Oct 10 '12 at 22:02

1 Answer 1

up vote 0 down vote accepted

Problem solved but I don't know why. Previously, I used this route for static files:

urlpatterns += staticfiles_urlpatterns()

and after set this custom route, everything is fine:

urlpatterns += patterns('',
    (r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': '/home/path_to/static'}),
)
share|improve this answer
1  
good job, you must be look at this page net.tutsplus.com/tutorials/python-tutorials/… –  vahid chakoshy Oct 17 '12 at 23:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.