Skip to content

Comments

Fix staticfiles finder in Windows failing when STATIC_URL is a full URL#94

Open
joaofrancese wants to merge 1 commit intojorgebastida:masterfrom
joaofrancese:master
Open

Fix staticfiles finder in Windows failing when STATIC_URL is a full URL#94
joaofrancese wants to merge 1 commit intojorgebastida:masterfrom
joaofrancese:master

Conversation

@joaofrancese
Copy link

I had a full URL as my STATIC_URL setting (something like http://www.example.com/static/) and I was getting 404s for /static/dajaxice/dajaxice.core.js when testing my site locally (with manage.py runserver). This commit fixed it for me. It seemed to happen because staticfiles.views.serve was handing down to Dajaxice's finder a path with forward slashes, whereas it was expecting a path with backwards slashes.

I had to do a bit of a hack in my urls.py to get staticfiles to serve my files even with a full URL in STATIC_URL (is there a better way? I'm not aware of one), so I guess this isn't a common use case.

def extract_path(prefix):
    import urlparse
    prefix = urlparse.urlparse(prefix).path
    if prefix[0] == '/':
        prefix = prefix[1:]
    return prefix

from django.conf.urls.static import static
prefix = extract_path(settings.STATIC_URL)
urlpatterns += static(prefix, view='django.contrib.staticfiles.views.serve')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant