Table Of Contents

Next topic

About django-files

This Page

Welcome to django-files documentation!

Thanks for checking out django-files. This project aims to be an easy, portable, pluggable and maintainable attachments framework for Django.

See the detailed table of contents for specific information.

Installation

From the Python package index (pypi)

$ pip install django-files

OR

$ easy_install django-files

From Git

$ git clone git://github.com/rhblind/django-files.git
$ cd django-files
$ python setup.py install

This will install django-files in your PYTHONPATH.

Note

If you are using virtualenv, remember to activate your environment before running the setup script.

Configuration

After you have installed django-files in your PYTHONPATH, you need to add it to your INSTALLED_APPS in your django project.

...
INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sites',
    ...
    'files',    # django-files attachments framework
    ...
)

You will also need to enable the django.contrib.auth, django.contrib.contenttypes and the django.contrib.sites apps, as they are used in the Attachment class.

Optional settings

DEFAULT_FILE_STORAGE

# Set the filesystem storage backend to use.

DEFAULT_FILE_STORAGE = "files.storage.SQLiteStorage"

This option set what kind of file storage backend you would like to use. If omitted, the default is django.core.files.storage.FileSystemStorage.

Valid backends are:

  • django.core.files.storage.FileSystemStorage
  • files.storage.SQLiteStorage
  • files.storage.PostgreSQLStorage

REQUIRE_AUTH_DOWNLOAD

# If this is set to True, users are required to be
# authenticated in addition to be have the "files.download_attachment"
# permission to be able to download files. Default is False.

REQUIRE_AUTH_DOWNLOAD = True

Attention

The next two options has no effect if using a database storage backend, as the file is stored directly in the database and will be wiped away when the row is deleted.

FORCE_FILE_RENAME

# If using the FileSystemStorage, setting this to True will
# append a FORCE_FILE_RENAME_POSTFIX postfix on files in the filesystem which
# has had their database reference deleted. Has no effect on
# database storage backends.

FORCE_FILE_RENAME = True

FORCE_FILE_RENAME_POSTFIX

# Set this to whatever you want your removed files to be
# appended with. Defaults to "_removed". This setting has no
# effect on the database storage backends, as they are gently
# killed.

FORCE_FILE_RENAME_POSTFIX = "_removed"

ATTACHMENT_MAX_SIZE

# Set the max allowed file size (in bytes) for attachments.
# If not set, no file size restrictions will be enforced.
# Note that this check will be performed after the file has
# been uploaded into the memory. Please make sure to protect your
# web server by setting (i.e. LimitRequestBody) to prevent uploading
# big files in memory.

ATTACHMENT_MAX_SIZE = 4194304  # 4 MB

Indices and tables