Comments (9)
New information on the header issue. I dug into the static package and added some debugging lines. The bad headers are generated when unicode strings are added for the Content-Type
header as shown below:
10:02:04 web.1 | Exception: [('Date', 'Mon, 03 Mar 2014 15:02:04 -0000'), ('Last-Modified', 'Mon, 03 Mar 2014 14:40:23 -0000'), ('ETag', '1393857623.0'), ('Content-Type', u'text/javascript')]
10:02:04 web.1 | [03/Mar/2014 10:02:04] "GET /static/js/application.min.d96c71a1463c.js HTTP/1.1" 500 59
I cannot trace back where this is coming from. Any other suggestions @kennethreitz?
from dj-static.
Just hearing about this now: lukearno/static#4
Static just uses mimetypes to guess the type, which does not appear to give unicode:
>>> import mimetypes
>>> mimetypes.guess_type('/foo.js')
('application/javascript', None)
I tried it in Python 2.7 and 3.3.
from dj-static.
I tried that as well and noticed it behaved correctly. There are two sections for guessing the content type:
# Cling
def _guess_type(self, full_path):
"""Guess the mime type using the mimetypes module."""
return mimetypes.guess_type(full_path)[0] or 'text/plain'
# Shock
def _guess_type(self, full_path):
"""Guess the mime type magically or using the mimetypes module."""
magic = self._match_magic(full_path)
if magic is not None:
return (mimetypes.guess_type(magic.old_path(full_path))[0]
or 'text/plain')
else:
return mimetypes.guess_type(full_path)[0] or 'text/plain'
I'm using Cling (assuming) with a stock implementation:
from django.core.wsgi import get_wsgi_application
from dj_static import Cling
application = Cling(get_wsgi_application())
from dj-static.
Does django-pipeline add mappings to mimetypes?
from dj-static.
Digging into that I see:
'PIPELINE_MIMETYPES': (
(b'text/coffeescript', '.coffee'),
(b'text/less', '.less'),
(b'application/javascript', '.js'),
(b'text/x-sass', '.sass'),
(b'text/x-scss', '.scss')
),
And then again in utils:
def guess_type(path, default=None):
for type, ext in settings.PIPELINE_MIMETYPES:
mimetypes.add_type(type, ext)
mimetype, _ = mimetypes.guess_type(path)
if not mimetype:
return default
return smart_str(mimetype)
I'm not sure how smart_str
works or the implication of having binary strings declared in PIPELINE_MIMETYPES
.
from dj-static.
I think that's it. Looks like it's fixed in the latest pipeline release (1.3.21).
jazzband/django-pipeline#297
jazzband/django-pipeline@f0b8f72
from dj-static.
I updated to 1.3.22 and this all appears to be working now. Yay for cross-package contamination of mimetypes..
from dj-static.
I just discovered an old version of pipeline in a project template and this being the first search result for the error saved me a lot of time. 👍
from dj-static.
Ditto - 👍
from dj-static.
Related Issues (20)
- Update docs to make clear Media files will not persist on heroku HOT 1
- Anyone else experiencing below error when running pip install dj-static HOT 1
- dj_static does not work with Django 1.7 dev server HOT 4
- dj-static works with runserver but not gunicorn? HOT 1
- Allow specifying subclass of `static.Cling` to use when creating `dj_static.cling` HOT 2
- Error when deploying to Heroku HOT 8
- Use original static library again as it's now Python 3 compatible HOT 2
- pypi version is out of date HOT 10
- Getting "Internal Server Error" with non-contrib `staticfiles` and DEBUG=True
- base_url option missing HOT 4
- ImportError: cannot import name get_path_info HOT 2
- 'module' object has no attribute Cling
- Static files not working on Heroku with Django 1.8
- When starting django server out of the root path, statics paths can fail HOT 1
- Cache-Control headers HOT 3
- django 1.9.x - doesn't work HOT 1
- New version for static/static3
- index.html not found in media_root
- CORS header on images HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dj-static.