Need help to render img in pdf from template using xhtml2pdf - django

I'm building a project were i need to get my data into pdf from a template (html), my problem is that the image is not apearing on pdf view.
This is my code:
class GeneratePdf_month(TemplateView):
template_name = "polls/info_month.html"
def get(self, request, *args, **kwargs):
## do some....
data = {
'cliente': cliente,
}
pdf = render_to_pdf(self.template_name, data)
return HttpResponse(pdf, content_type='application/pdf')
## and this is my html template
<head>
{% load staticfiles %}
<title>Detail</title>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
padding: 10px;
}
</style>
</head>
<body>
<header>BlaBla<img src="{% static 'polls/images/image.png'%}"></header>
</body
Can someone help me?

If your are using xhtmltopdf you also need to provide a link_callback for being abble to display images:
def link_callback(uri, rel):
"""
Convert HTML URIs to absolute system paths so xhtml2pdf can access those
resources
"""
# use short variable names
sUrl = settings.STATIC_URL # Typically /static/
#static Root
sRoot = settings.STATIC_ROOT # Typically /home/userX/project_static/
mUrl = settings.MEDIA_URL # Typically /static/media/
mRoot = settings.MEDIA_ROOT # Typically /home/userX/project_static/media/
# convert URIs to absolute system paths
if uri.startswith(mUrl):
path = os.path.join(mRoot, uri.replace(mUrl, ""))
elif uri.startswith(sUrl):
path = os.path.join(sRoot, uri.replace(sUrl, ""))
else:
return uri # handle absolute uri (ie: http://some.tld/foo.png)
# make sure that file exists
if not os.path.isfile(path):
raise Exception(
'media URI must start with %s or %s' % (sUrl, mUrl)
)
return path
AND don't forget to add the link callback in your render_to_pdf:
def render_to_pdf(template_src, context_dict={}):
template = get_template(template_src)
html = template.render(context_dict)
result = BytesIO()
pdf = pisa.pisaDocument(BytesIO(html.encode("ISO-8859-1")), result, link_callback=link_callback)
if not pdf.err:
return HttpResponse(result.getvalue(), content_type='application/pdf')
return None
You also need to specify the height and widht inside the img tag like:
<img src="{% static 'polls/images/image.png'%}" alt="image" width="200" height="150" />
In settings.py don't forget to define your STATIC_URL AND STATIC_ROOT, MEDIA_URL AND MEDIA_ROOT
Like this for exemple:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR,'project_name/static/')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR,'project_name/media/')
Then don't forget to run python manage.py collectstatic in the terminal
More info here: https://xhtml2pdf.readthedocs.io/en/latest/usage.html#using-xhtml2pdf-in-django

in views.py
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent
path = os.path.join( BASE_DIR , 'static')
# send 'path' first in context
context = {'path':path , 'any':any }
in template
<img src="{{path}}\img\pic.png" >

Related

TemplateDoesNotExist at / (home.html)

I'm working on an example Placeholder Image Server. This uses a single file approach, so urls, views, settings, are all in just one file called placeholder.py.
Each time I try visiting http://localhost:8000 (the homepage), I get TemplateDoesNotExist at / thrown at me. I can't figure out what's wrong. Below is the project structure:
/placeholder
placeholder.py
/templates
home.html
/static
style.css
Here's the content of each file:
placeholder.py
import hashlib
import os
import sys
from io import BytesIO
from PIL import Image, ImageDraw
from django.conf import settings
from django import forms
from django.urls import path, reverse
from django.core.cache import cache
from django.core.wsgi import get_wsgi_application
from django.http import HttpResponse, HttpResponseBadRequest
from django.shortcuts import render
from django.views.decorators.http import etag
from django.core.management import execute_from_command_line
# settings likely to change between environments
DEBUG = os.environ.get('DEBUG', 'on') == 'on'
SECRET_KEY = os.environ.get('SECRET_KEY', 'soj-4^4nho$ifsxsoi1+a8&6o&dya)tcivwcg9g_82&8sg*q^9')
ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS', 'localhost').split(',')
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# settings
settings.configure(
DEBUG=DEBUG,
SECRET_KEY=SECRET_KEY,
ALLOWED_HOSTS=ALLOWED_HOSTS,
ROOT_URLCONF=__name__,
MIDDLEWARE_CLASSES=(
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
),
INSTALLED_APPS=(
'django.contrib.staticfiles',
),
TEMPLATES=[
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': os.path.join(BASE_DIR, 'templates'),
}
],
STATICFILES_DIRS=(
os.path.join(BASE_DIR, 'static'),
),
STATIC_URL='/static/',
)
# simple form to validate the height and width of an image
class ImageForm(forms.Form):
'''form to validate requested placeholder image'''
width = forms.IntegerField(min_value=1, max_value=2000)
height = forms.IntegerField(min_value=1, max_value=2000)
def generate(self, image_format='PNG'):
'''generate an image of the given type and return as raw bytes'''
width = self.cleaned_data['width']
height = self.cleaned_data['height']
key = '{}.{}.{}'.format(width, height, image_format)
content = cache.get(key)
if content is None:
image = Image.new('RGB', (width, height))
draw = ImageDraw.Draw(image)
text = '{} x {}'.format(width, height)
textwidth, textheight = draw.textsize(text)
if textwidth < width and textheight < height:
texttop = (height - textheight) // 2
textleft = (width - textwidth) // 2
draw.text((textleft, texttop), text, fill=(255, 255, 255))
content = BytesIO()
image.save(content, image_format)
content.seek(0)
cache.set(key, content, 60 * 60)
return content
# for client-side caching
def generate_etag(request, width, height):
content = 'Placeholder: {0} x {1}'.format(width, height)
return hashlib.sha1(content.encode('utf-8')).hexdigest()
# views
def index(request):
example = reverse('placeholder', kwargs={'width':50, 'height':50})
context = {
'example' : request.build_absolute_uri(example)
}
return render(request, 'home.html', context)
#etag(generate_etag) # decorator for client-side caching
def placeholder(request, width, height):
form = ImageForm({'width':width, 'height':height})
if form.is_valid():
image = form.generate()
return HttpResponse(image, content_type='image/png')
else:
return HttpResponseBadRequest('<h1>Invalid Image Request!</h1>')
# the url
urlpatterns = [
path('', index, name='homepage'),
path('image/<int:width>x<int:height>', placeholder, name='placeholder'),
]
# wsgi application
application = get_wsgi_application()
# relevant part from manage.py
if __name__ == "__main__":
execute_from_command_line(sys.argv)
home.html
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Demo Placeholder Images</title>
<link type="text/css" rel="stylesheet" href="{% static 'style.css' %}">
</head>
<body>
<h1>Demo Placeholder Images</h1>
<p>This server can be used for serving placeholder images for any webpage.</p>
<p>To request a placeholder image of a given width and height simply include
an image with the source pointing to <b>/placeholder/<width>x
<height>/</b> on this server such as:
</p>
<pre><img src="{{ example }}"></pre>
<h2>Examples</h2>
<ul>
<li><img src="{% url 'placeholder' width=50 height=50 %}"></li>
<li><img src="{% url 'placeholder' width=100 height=50 %}"></li>
<li><img src="{% url 'placeholder' width=50 height=100 %}"></li>
</ul>
</body>
</html>
What's wrong?
I think the problem is that your BASE_DIR is incorrect. Because you have one simple flat file, and templates and static files are in subdirectories at the same level, you only need to go to the current directory, not the parent. So it should be:
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
I figured it out. The value of 'DIRS' in the TEMPLATES setting is meant to be a list. Here's what I mean:
...
TEMPLATES=[
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'templates'),
],
}
],
...

Images not loading Django website

Images on my django website are not loading for some reason
This is my models.py
thumbnail = models.ImageField(upload_to='images/',blank=True)
This is my settings.py lines
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
if DEBUG:
STATIC_ROOT = os.path.join(BASE_DIR, 'static/static-only')
MEDIA_ROOT = os.path.join(BASE_DIR, 'static/media')
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static/static'),
)
This is my views.py
class BlogIndex(generic.ListView):
queryset = models.Entry.objects.published()
template_name = "index.html"
paginate_by = 5
In url.py
if settings.DEBUG:
urlpatterns +=static(settings.STATIC_URL,document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)
In index.html i did this
<img class="img-rounded" src = "{{object.thumbnail.url}}"/>
pip freeze
Django==1.11.2
django-ckeditor==5.2.2
django-crispy-forms==1.6.1
django-markdown==0.8.4
django-pagedown==0.1.3
Markdown==2.6.8
olefile==0.44
Pillow==4.1.1
The Images are getting saved in the static/media/images directory
But the images are not loading in the web page...
When i try to right-click and view the image It shows this error SCREEN SHOT
Other objects are working perfectly.. Only the images aren't loading
You need the media url in the src:
<img class="img-rounded" src = "{{object.thumbnail.url}}"/>
should be:
<img class="img-rounded" src = "{{MEDIA_URL}}{{object.thumbnail.url}}"/>
or something similar
<img class="img-rounded" src = "/static/media/uploads/{{object.thumbnail.url}}"/>
The Issue is fixed, (Got assistance from a facebook group)
The issue was a url pattern in the views.py
The screen shot that I put had a line
Raised by : blog.views.Blogdetail
Apparently i had a urlpattern
url(r'^(?P<slug>\S+)/$', views.BlogDetail.as_view(), name='entry_detail'),
My pattern for blog detail view has match \S+ - so any string of characters that has no spaces in
Which will match pretty much any pattern that hasn't matched previously and any other url pattern which are below this particular url will not be accessed
Changed the url pattern to the following and I was good to go
url(r'^(?P<slug>[-\w]+)/$', views.BlogDetail.as_view(),name='entry_detail'),
settings.py:
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
in this model you can see Overwrite of exist IMG, return img as base string:
models.py
from django.db import models
from django.core.files.storage import FileSystemStorage
from base64 import b64encode, b64decode
class OverwriteStorage(FileSystemStorage):
def get_available_name(self, name, max_length=700):
if self.exists(name):
os.remove(os.path.join(settings.MEDIA_ROOT, name))
return name
def upload_location(instance, filename):
return os.path.join('defaultfolder', instance.phone, filename)
class ImgModel(models.Model):
name= models.CharField(max_length=100)
img = models.FileField(storage=OverwriteStorage(),
upload_to=phone_upload_location,
null=True,
blank=True,
max_length=700)
def image_to_base64(self, model_picture_path):
if model_picture_path:
try:
with open(model_picture_path.path, "rb") as imageFile:
str = b64encode(imageFile.read())
return "data:image/jpg;base64,%s" % str.decode()
except IOError:
return model_picture_path.url
else:
return None
.html
<img src="{{ MEDIA_URL }}foo.jpg">
I faced this issue and I tried lot of things but imges wont load then I tried out a simple trick but this did the job. What I did was, in my settings.py file, I included the STATIC_DIR varaible just after BASE_DIR. Below is my settings.py file
Settings.py
#Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_DIR=os.path.join(BASE_DIR,'templates')
STATIC_DIR=os.path.join(BASE_DIR,"static")
#Other content
STATIC_URL = '/static/'
STATICFILES_DIRS=(
STATIC_DIR,
)
Check this out maybe this will help!
How to fix images answer is
mention above index.html
{% static 'travello/images/' as baseUrl %}
path
then

UncompressableFileError: 'scripts/app.js' isn't accessible via COMPRESS_URL ('http://my-bucket.s3-us-west-2.amazonaws.com/') and can't be compressed

I'm trying to use django-compressor and django-storages-redux together with django staticfiles and Amazon S3. These are my settings:
STATIC_URL = COMPRESS_URL = 'http://my-bucket.s3-us-west-2.amazonaws.com/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'compressor.finders.CompressorFinder',
)
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'site-static'),
)
COMPRESS_PRECOMPILERS = (
('text/scss', 'sass --scss --compass {infile} {outfile}'),
)
COMPRESS_CSS_FILTERS = [
'compressor.filters.css_default.CssAbsoluteFilter',
'compressor.filters.cssmin.CSSMinFilter',
]
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
STATICFILES_STORAGE = COMPRESS_STORAGE = 'myapp.apps.mymodel.storage.CachedS3BotoStorage'
COMPRESS_OUTPUT_DIR = 'cache'
COMPRESS_ENABLED = False
AWS_S3_HOST = "s3-us-west-2.amazonaws.com"
AWS_ACCESS_KEY_ID = '---'
AWS_SECRET_ACCESS_KEY = '---'
AWS_STORAGE_BUCKET_NAME = 'my-bucket'
AWS_QUERYSTRING_AUTH = False
AWS_S3_CUSTOM_DOMAIN = 'my-bucket.s3-us-west-2.amazonaws.com'
For staticfiles I use a custom storage backend, as advised here http://django-compressor.readthedocs.org/en/latest/remote-storages/
from django.core.files.storage import get_storage_class
from storages.backends.s3boto import S3BotoStorage
class CachedS3BotoStorage(S3BotoStorage):
"""
S3 storage backend that saves the files locally, too.
"""
def __init__(self, *args, **kwargs):
super(CachedS3BotoStorage, self).__init__(*args, **kwargs)
self.local_storage = get_storage_class('compressor.storage.CompressorFileStorage')()
def save(self, name, content):
name = super(CachedS3BotoStorage, self).save(name, content)
self.local_storage._save(name, content)
return name
First I ran python manage.py collectstatic which worked well and copied all the files to S3.
Now I have a simple template like that:
{% load compress static %}
<html><head>
{% compress js %}
<script src="scripts/app.js"></script>
<script src="scripts/controllers/main.js"></script>
{% endcompress %}
</head><body></body></html>
Opening that connected django view in a browser gives me the following exception:
'scripts/app.js' isn't accessible via COMPRESS_URL ('http://my-bucket.s3-us-west-2.amazonaws.com/') and can't be compressed
But the file is there and accessible (via http and https). The exception is raised here: https://github.com/django-compressor/django-compressor/blob/2.0/compressor/base.py#L82
Seems like get_basename(self, url) (https://github.com/django-compressor/django-compressor/blob/2.0/compressor/base.py#L72) already receives a relative url here.
Anybody knows how to fix that?
Thanks in advance!
Seems like get_basename(self, url)
(https://github.com/django-compressor/django-compressor/blob/2.0/compressor/base.py#L72)
already receives a relative url here.
That is the problem. Using the static template tag to get absolute URL should fix this.
{% load compress static %}
<html><head>
{% compress js %}
<script src="{% static "scripts/app.js" %}"></script>
<script src="{% static "scripts/controllers/main.js" %}"></script>
{% endcompress %}
</head><body></body></html>
You might also want to look at this answer https://stackoverflow.com/a/18400426

Image not working while converting html to pdf

I want to convert one html page into pdf in django web- framework , everthing is working good except image .
Here is small snippet of HTML page which I want to convert into pdf
<div class="certi-description"> <img src="/media/certificate/icons/2.jpg" style="width: 12%;height: 25%;position: absolute; left: {{tag_logo_offset.0|add:'-355'}}px; top: {{tag_logo_offset.1|add:'-170'}}px;"><br>
<div style="position: absolute; left: {{tag_name_offset.0|add:'-355'}}px; top: {{tag_name_offset.1|add:'-170'}}px;"><div id="tag" ><center><font size="3" color="red">{{ tag_name}}</font><center></div></div><br><br>
<div style="position: absolute; left: {{comm_offset.0|add:'-355'}}px; top: {{comm_offset.1|add:'-170'}}px;"><span><font size="5" color="black">is hereby Rewarded to</font></span></div><br>
Here is code snippet in views.py
template = certi.generic_certificate.template_name
template_new = get_template(template)
context_dict = Context(context)
html = template_new.render(context_dict)
print html
result = StringIO.StringIO()
links = lambda uri, rel: os.path.join(base.MEDIA_ROOT, uri.replace(base.MEDIA_ROOT, ''))
print base.MEDIA_ROOT
pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("UTF-8")),dest=result, link_callback=links)
if not pdf.err:
converted_pdf= HttpResponse(result.getvalue(), content_type='application/pdf')
converted_pdf['Content-Disposition'] = 'attachment; filename="certificate%s.pdf"'%certi_id
p = canvas.Canvas(converted_pdf)
p.showPage()
p.save()
pdf = result.getvalue()
result.close()
myfile = ContentFile(pdf)
Certificate.objects.filter(pk=certi_id).update(pdf_template = p)
converted_pdf.write(pdf)
return converted_pdf
base.py as my settings file :
MEDIA_ROOT = normpath(join(DJANGO_ROOT, 'media'))
MEDIA_URL = '/media/'
########## END MEDIA CONFIGURATION
AUTHENTICATION_BACKENDS = ('custom.backends.EmailOrUsernameModelBackend',)
########## STATIC FILE CONFIGURATION
STATIC_ROOT = normpath(join(DJANGO_ROOT, 'final_static'))
STATIC_URL = '/static/'
I have several images in /media/certificate/icons folder like 2.jpg which I am using in my html
Everthing is converting to pdf except image. I have checked all possible paths but still not working.
Please help to solve this issue.

Using static images with sorl-thumbnail

I am trying to serve the thumbnail of a file that resides in my STATIC_ROOT folder. It doesn't really matter if it ends up in MEDIA_URL/cache, but sorl-thumbnail will not load the image from the static folder.
current code:
{% thumbnail "images/store/no_image.png" "125x125" as thumb %}
hack that works
{% thumbnail "http://localhost/my_project/static/images/store/no_image.png" "125x125" as thumb %}
I don't like the hack because
A) It is not dry (my project is actually served from a sub-directory of /
B) It is using http to grab a file that is only 3 directories away, seems pointlessly inefficient
I worked around this by passing through a file to the template context from my view.
Here is an example util function I called from my views:
def get_placeholder_image():
from django.core.files.images import ImageFile
from django.core.files.storage import get_storage_class
storage_class = get_storage_class(settings.STATICFILES_STORAGE)
storage = storage_class()
placeholder = storage.open(settings.PLACEHOLDER_IMAGE_PATH)
image = ImageFile(placeholder)
image.storage = storage
return image
You could probably do something similar as a custom template tag.
Template filter works. But I am not sure, whether there is each time reading from storage. If so, it is unreasonably...
from django.template import Library
from django.core.files.images import ImageFile
from django.core.files.storage import get_storage_class
register = Library()
#register.filter
def static_image(path):
"""
{% thumbnail "/img/default_avatar.png"|static_image "50x50" as img %}
<img src="{{ MEDIA_URL }}{{img}}"/>
{% endthumbnail %}
"""
storage_class = get_storage_class(settings.STATICFILES_STORAGE)
storage = storage_class()
image = ImageFile(storage.open(path))
image.storage = storage
return image
Assuming you are using Django 1.3 you should take a look at the docs about Managing static files
If you setup everything correctly, you can include your images like this:
<img src="{{ STATIC_URL }}images/store/no_image.png" />
I ended up hijacking the fact that it can get from a URL, and wrote my own tag that overrides the _render method on the ThumbnailNode:
from django.template import Library
from django.contrib.sites.models import Site
from django.contrib.sites.models import get_current_site
from sorl.thumbnail.templatetags.thumbnail import ThumbnailNode as SorlNode
from sorl.thumbnail.conf import settings
from sorl.thumbnail.images import DummyImageFile
from sorl.thumbnail import default
register = Library()
class ThumbnailNode(SorlNode):
"""allows to add site url prefix"""
def _render(self, context):
file_ = self.file_.resolve(context)
if isinstance(file_, basestring):
site = get_current_site(context['request'])
file_ = "http://" + site.domain + file_
geometry = self.geometry.resolve(context)
options = {}
for key, expr in self.options:
noresolve = {u'True': True, u'False': False, u'None': None}
value = noresolve.get(unicode(expr), expr.resolve(context))
if key == 'options':
options.update(value)
else:
options[key] = value
if settings.THUMBNAIL_DUMMY:
thumbnail = DummyImageFile(geometry)
elif file_:
thumbnail = default.backend.get_thumbnail(
file_, geometry, **options
)
else:
return self.nodelist_empty.render(context)
context.push()
context[self.as_var] = thumbnail
output = self.nodelist_file.render(context)
context.pop()
return output
#register.tag
def thumbnail(parser, token):
return ThumbnailNode(parser, token)
Then from the template:
{% with path=STATIC_URL|add:"/path/to/static/image.png" %}
{% thumbnail path "50x50" as thumb %}
<img src="{{ thumb.url }}" />
...
Not the neatest solution... :-/
The default value of setting sorl THUMBNAIL_STORAGE is the same settings.DEFAULT_FILE_STORAGE.
You must create storage that uses STATIC_ROOT, for example you can use 'django.core.files.storage.FileSystemStorage' and instantiate with location=settings.STATIC_ROOT and base_url=settings.STATIC_URL
Only THUMBNAIL_STORAGE set in settings for a 'MyCustomFileStorage' did not work. So I had to do to DEFAULT_FILE_STORAGE and it worked.
Define in settings.py:
DEFAULT_FILE_STORAGE = 'utils.storage.StaticFilesStorage'
utils/storage.py:
import os
from datetime import datetime
from django.conf import settings
from django.core.files.storage import FileSystemStorage
from django.core.exceptions import ImproperlyConfigured
def check_settings():
"""
Checks if the MEDIA_(ROOT|URL) and STATIC_(ROOT|URL)
settings have the same value.
"""
if settings.MEDIA_URL == settings.STATIC_URL:
raise ImproperlyConfigured("The MEDIA_URL and STATIC_URL "
"settings must have different values")
if (settings.MEDIA_ROOT == settings.STATIC_ROOT):
raise ImproperlyConfigured("The MEDIA_ROOT and STATIC_ROOT "
"settings must have different values")
class TimeAwareFileSystemStorage(FileSystemStorage):
def accessed_time(self, name):
return datetime.fromtimestamp(os.path.getatime(self.path(name)))
def created_time(self, name):
return datetime.fromtimestamp(os.path.getctime(self.path(name)))
def modified_time(self, name):
return datetime.fromtimestamp(os.path.getmtime(self.path(name)))
class StaticFilesStorage(TimeAwareFileSystemStorage):
"""
Standard file system storage for static files.
The defaults for ``location`` and ``base_url`` are
``STATIC_ROOT`` and ``STATIC_URL``.
"""
def __init__(self, location=None, base_url=None, *args, **kwargs):
if location is None:
location = settings.STATIC_ROOT
if base_url is None:
base_url = settings.STATIC_URL
if not location:
raise ImproperlyConfigured("You're using the staticfiles app "
"without having set the STATIC_ROOT setting. Set it to "
"the absolute path of the directory that holds static files.")
# check for None since we might use a root URL (``/``)
if base_url is None:
raise ImproperlyConfigured("You're using the staticfiles app "
"without having set the STATIC_URL setting. Set it to "
"URL that handles the files served from STATIC_ROOT.")
if settings.DEBUG:
check_settings()
super(StaticFilesStorage, self).__init__(location, base_url, *args, **kwargs)
Reference:
https://github.com/mneuhaus/heinzel/blob/master/staticfiles/storage.py
https://docs.djangoproject.com/en/dev/ref/settings/#default-file-storage