The easiest way to get django-filer
is simply install it with pip:
$ pip install django-filer
If you are feeling adventurous you can get the latest sourcecode from github
- Django 1.2
- django-mptt >= 0.2.1
- easy_thumbnails >= 1.0-alpha-17
- django-polymorphic >= 0.2
- PIL 1.1.7 (with JPEG and ZLIB support) I recommend using Pillow instead.
- django-staticfiles or
django.contrib.staticfiles
with Django 1.3 is recommended
Since the PIL package on `pypi`_ can be notoriously hard to install on some
platforms it is not listed in the package dependencies in setup.py
and won't
be installed automatically. Please make sure you install PIL with JPEG and
ZLIB support installed. I recommend the better packaged Pillow a better
packaged fork of PIL).
Add "filer"
to your project's INSTALLED_APPS
setting and run manage.py syncdb
(or manage.py migrate
if you're using South).
Note that easy_thumbnails also has database tables and needs a syncdb
or
migrate
.
In order to operate properly, django-filer needs some js and css files. They
are located in the static/filer
directory in the filer
package. If you are
already using django-staticfiles or django.contrib.staticfiles you're
already set and can skip the next paragraph.
By default django-filer will look for those files at <MEDIA_URL>/filer/
.
Make sure that they are accessible at one of those locations.
See the :ref:`FILER_STATICMEDIA_PREFIX` setting if you want to serve them from
somewhere else.
django-filer supports permissions on files. They can be enabled or disabled.
Files with disabled permissions are your regular world readable files in
MEDIA_ROOT
. Files with permissions are a other case however. To be able to
check permissions on the file downloads a special view is used and they are
saved in a separate location (in a directory called smedia next to
MEDIA_ROOT
by default).
filer.server.urls
needs to be included in the root urls.py
:
urlpatterns += patterns('', url(r'^', include('filer.server.urls')), )
By default files with permissions are served directly by django. That is acceptable in a development environment, but very bad for performance in production. See the docs on :ref:`how to serve files more efficiently <server>`.
It is possible to define the important part of an image (the subject location) in the admin interface for django-filer images. This is very useful when later resizing and cropping images with easy_thumbnails. The image can then be cropped autamatically in a way, that the important part of the image is always visible.
To enable automatic subject location aware cropping of images replace
easy_thumbnails.processors.scale_and_crop
with
filer.thumbnail_processors.scale_and_crop_with_subject_location
in the
THUMBNAIL_PROCESSORS
setting:
THUMBNAIL_PROCESSORS = ( 'easy_thumbnails.processors.colorspace', 'easy_thumbnails.processors.autocrop', #'easy_thumbnails.processors.scale_and_crop', 'filer.thumbnail_processors.scale_and_crop_with_subject_location', 'easy_thumbnails.processors.filters', )
To crop an image and respect the subject location:
{% load thumbnails %} {% thumbnail obj.img 200x300 crop upscale subject_location=obj.img.subject_location %}