Opened 10 years ago

Closed 10 years ago

#21947 closed Bug (duplicate)

Test server returns HTTP 500 on static files when STATIC_ROOT is None

Reported by: madmox Owned by: nobody
Component: contrib.staticfiles Version: 1.6
Severity: Normal Keywords: STATIC_ROOT runserver test server
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I observed that my development server returned HTTP 500 status codes for all static files since I changed a bit of configuration in my settings.py file:

settings.py file before modification:

...
if not DEBUG:
    STATIC_ROOT = os.environ.['DJANGO_STATIC_ROOT']
...

settings.py file after modification:

...
STATIC_ROOT = os.environ.get('DJANGO_STATIC_ROOT', None)
...

In my development environment, I don't set the 'DJANGO_STATIC_ROOT' environment variable since I only use the test server which is supposed to collect static files on the fly in the static dirs in the different apps. Here is the resulting exception and stack trace in the runserver window when I try to access a static file:

Traceback (most recent call last):
  File "/usr/lib/python3.3/wsgiref/handlers.py", line 137, in run
    self.result = application(self.environ, self.start_response)
  File "/home/madmox/.virtualenvs/django-dev/lib/python3.3/site-packages/django/contrib/staticfiles/handlers.py", line 68, in __call__
    return super(StaticFilesHandler, self).__call__(environ, start_response)
  File "/home/madmox/.virtualenvs/django-dev/lib/python3.3/site-packages/django/core/handlers/wsgi.py", line 206, in __call__
    response = self.get_response(request)
  File "/home/madmox/.virtualenvs/django-dev/lib/python3.3/site-packages/django/contrib/staticfiles/handlers.py", line 58, in get_response
    return self.serve(request)
  File "/home/madmox/.virtualenvs/django-dev/lib/python3.3/site-packages/django/contrib/staticfiles/handlers.py", line 51, in serve
    return serve(request, self.file_path(request.path), insecure=True)
  File "/home/madmox/.virtualenvs/django-dev/lib/python3.3/site-packages/django/contrib/staticfiles/views.py", line 35, in serve
    absolute_path = finders.find(normalized_path)
  File "/home/madmox/.virtualenvs/django-dev/lib/python3.3/site-packages/django/contrib/staticfiles/finders.py", line 238, in find
    for finder in get_finders():
  File "/home/madmox/.virtualenvs/django-dev/lib/python3.3/site-packages/django/contrib/staticfiles/finders.py", line 253, in get_finders
    yield get_finder(finder_path)
  File "/home/madmox/.virtualenvs/django-dev/lib/python3.3/site-packages/django/utils/functional.py", line 32, in wrapper
    result = func(*args)
  File "/home/madmox/.virtualenvs/django-dev/lib/python3.3/site-packages/django/contrib/staticfiles/finders.py", line 265, in _get_finder
    return Finder()
  File "/home/madmox/.virtualenvs/django-dev/lib/python3.3/site-packages/django/contrib/staticfiles/finders.py", line 60, in __init__
    if os.path.abspath(settings.STATIC_ROOT) == os.path.abspath(root):
  File "/home/madmox/.virtualenvs/django-dev/lib/python3.3/posixpath.py", line 379, in abspath
    if not isabs(path):
  File "/home/madmox/.virtualenvs/django-dev/lib/python3.3/posixpath.py", line 64, in isabs
    return s.startswith(sep)
AttributeError: 'NoneType' object has no attribute 'startswith'
[04/Feb/2014 03:35:03] "GET /static/about/css/app.css HTTP/1.1" 500 59

This is a little bit unexpected since the documentation states the default value for STATIC_ROOT is None.

Change History (4)

comment:1 by loic84, 10 years ago

Hi @madmox, the default value for STATIC_ROOT has been changed from '' to None as a result of #21581.

This fix has been backported to the 1.6.x branch due to the severity of the issue, but we haven't made a new release yet, so the documentation applies to Django 1.6.2 which hasn't been released.

I'm not sure how to best deal with this situation at Django's level, especially if a new release is not imminent. In the meantime, you may set STATIC_ROOT to any string value, but if you choose an empty string '' I strongly recommend you refrain from using the --clear option.

comment:2 by Tim Graham, 10 years ago

Will this be resolved by #21581 then? If all goes well, I expect 1.6.2 to be released within a week.

comment:3 by loic84, 10 years ago

@timo yes, that'll fix it.

comment:4 by Tim Graham, 10 years ago

Resolution: duplicate
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top