Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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