In your local_settings.py you should set/change at least these things:

  • MEDIA_ROOT
  • DATABASES
  • SECRET_KEY
  • MANAGERS
  • CACHES The default PyLucid settings used the LocMemCache backend. But this isn't very memory-efficient. (see below)

If you use our create a new page instance script, some values are prefilled for you in the created instance.

local_settings.py example

Here a example local_settings.py
The newest version is always here: https://github.com/jedie/PyLucid/blob/master/scripts/local_settings_example.py

Database connection settings

see also:

minimal MySQL example:

1
2
3
4
5
6
7
8
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'Database Name',
        'USER': 'Username',
        'PASSWORD': 'User Password',
    }
}

CACHES

The default PyLucid settings used the LocMemCache backend. But this isn't very memory-efficient.

Existing cache backends (from django-tools 'smooth cache backends') are:

FileBasedCache django_tools.cache.smooth_cache_backends.SmoothFileBasedCache
DatabaseCache django_tools.cache.smooth_cache_backends.SmoothDatabaseCache
LocMemCache django_tools.cache.smooth_cache_backends.SmoothLocMemCache
MemcachedCache django_tools.cache.smooth_cache_backends.SmoothMemcachedCache
PyLibMCCache django_tools.cache.smooth_cache_backends.SmoothPyLibMCCache

You can also used the normal django cache backends. But PyLucid clears the cache with cache.clear() completely after e.g. a page was edited. This isn't effective with the normal cache backends. More info in the django-tools 'smooth cache backends' README.

Easy to setup is the FileBasedCache backend. Example settings can look like:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
CACHE_MIDDLEWARE_SECONDS = 3600 # 1h

_BACKEND = "django_tools.cache.smooth_cache_backends.SmoothFileBasedCache "
_LOCATION_PREFIX = "/var/tmp/PyLucid_"
CACHES = {
    'default': {
        'BACKEND': _BACKEND,
        'LOCATION': _LOCATION_PREFIX + 'default-cache',
        'TIMEOUT': CACHE_MIDDLEWARE_SECONDS,
    },
    'dbtemplates': {
        # http://django-dbtemplates.readthedocs.org/en/latest/advanced/#caching
        'BACKEND': _BACKEND,
        'LOCATION': _LOCATION_PREFIX + 'dbtemplates-cache',
        'TIMEOUT': CACHE_MIDDLEWARE_SECONDS,
    },
    LOCAL_SYNC_CACHE_BACKEND: {
        # https://github.com/jedie/django-tools/blob/master/django_tools/local_sync_cache/local_sync_cache.py
        'BACKEND': _BACKEND,
        'LOCATION': _LOCATION_PREFIX + 'local_sync-cache',
        'TIMEOUT': CACHE_MIDDLEWARE_SECONDS,
    },
}

Note:

flexible FileBasedCache settings

The a code snippet if you would like to use the FileBasedCache backend and set the path dynamically:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# see: http://docs.djangoproject.com/en/dev/topics/cache/#setting-up-the-cache
#
# You can test if cache works, with:
#     PyLucid admin menu / system / base check
#
CACHE_MIDDLEWARE_SECONDS = 3600 # 1h
#
_BACKEND = "django_tools.cache.smooth_cache_backends.SmoothFileBasedCache "
# use smooth cache from django-tools:
# https://github.com/jedie/django-tools/tree/master/django_tools/cache#smooth-cache-backends
#
_CACHE_PATH_PREFIX = os.environ.get("USERNAME", "PyLucid")
# Change it with e.g. your username to make this cache "unique" on the server.
# This can be usefull on shared webhosting.
#
_CACHE_PATH_SUFFIX = str(SITE_ID)
# Must not changed.
#
_CACHE_PATH_MODE = 0700
# Default mode for cache directory is 0700 -> Useable only for current user.
# Change to 0777 if web process runs e.g. with nobody!
#
def _get_and_create_tempdir_location(entry):
    """
    Little helper for easy setup a cache filesystem path in temp.
    Try global temp directory, "tmp" in users's home or "tmp" in current working dir
    """
    possible_paths = (tempfile.gettempdir(), os.path.expanduser("~/tmp"), "tmp")
    sub_dir = "%s_%s_%s" % (_CACHE_PATH_PREFIX, entry, _CACHE_PATH_SUFFIX)
    for path in possible_paths:
        path = os.path.join(path, sub_dir)
        try:
            if not os.path.exists(path):
                os.makedirs(path, _CACHE_PATH_MODE)
            else:
                os.chmod(path, _CACHE_PATH_MODE)
        except:
            continue
        else:
            return path
    raise SystemError("Can't get a temp directory, tried: %s" % repr(possible_paths))

CACHES = {
    'default': {
        'BACKEND': _BACKEND,
        'LOCATION': _get_and_create_tempdir_location("default_cache"),
        'TIMEOUT': CACHE_MIDDLEWARE_SECONDS,
    },
    'dbtemplates': {
        # http://django-dbtemplates.readthedocs.org/en/latest/advanced/#caching
        'BACKEND': _BACKEND,
        'LOCATION': _get_and_create_tempdir_location("dbtemplates_cache"),
        'TIMEOUT': CACHE_MIDDLEWARE_SECONDS,
    },
    'local_sync_cache': {
        # https://github.com/jedie/django-tools/blob/master/django_tools/local_sync_cache/local_sync_cache.py
        'BACKEND': _BACKEND,
        'LOCATION': _get_and_create_tempdir_location("local_sync_cache"),
        'TIMEOUT': CACHE_MIDDLEWARE_SECONDS,
    }
}