#19046: staticfiles not finding the files on Windows
-------------------------------------+------------------------------------
     Reporter:  nelutzu_13@…         |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  contrib.staticfiles  |                  Version:  1.4
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+------------------------------------
Changes (by aaugustin):

 * severity:  Release blocker => Normal
 * easy:  1 => 0


Comment:

 It wasn't easy but I eventually managed to reproduce this problem.

 Here's what I did:
 - Install VirtualBox, Windows, Python, Git, etc.
 - Start a new project
 - Set `STATIC_ROOT = './static'` '''(no trailing slash -- otherwise the
 bug doesn't happen)''', `STATICFILES_DIRS = ('./static_src/',)`
 - Comment out a few lines in `django/conf/__init__.py` to cancel the
 effects of fbfaa35fb0a2a1206221e00c56cf6136cf93b6f1 -- otherwise Django
 refuses to start
 - Create a file `static_src/yay.txt`
 - Launch the development server and go to
 `http://localhost:8000/static/yay.txt`

 ----

 Since fbfaa35fb0a2a1206221e00c56cf6136cf93b6f1, Django requires
 `STATIC_URL` to end with a slash, so this problem cannot occur in Django
 1.5. For this reason, I'm going to downgrade the severity.

 ----

 However, I still feel there's something wrong with this line:

 {{{
 normalized_path = posixpath.normpath(unquote(path)).lstrip('/')
 }}}

 As far as I can tell:
 - The undocumented `posixpath` module from Python's standard library is
 used to perform path normalization with forward slashes, which seems
 suitable for URLs;
 - The `.lstrip('/')` is intended to strip the leading slash from the URL,
 in case `STATIC_URL` setting doesn't end in a slash.

 I see two problems:
 - In the situation described above, the `serve()` function receives `path
 = '\yay.txt'` — the backslash has absolutely no reason for being here;
 everything's happening in "URL-space", not in "file-space" until this
 point;
 - The `.lstrip('/')` isn't necessary any longer since Django >= 1.5
 requires `STATIC_URL` to end in a slash.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/19046#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to