Welcome | Get started | Dive into Lino | Contribute | Topics | Reference | More

More about the Site class

Here are the Django settings that Lino puts into the global context of a settings module:

>>> from lino_book.projects.min9.settings import Site
>>> pseudoglobals = {}
>>> SITE = Site(pseudoglobals)
>>> sorted(pseudoglobals.keys())
... 
['AUTHENTICATION_BACKENDS', 'AUTH_USER_MODEL', 'DATABASES',
'DEFAULT_AUTO_FIELD', 'FIXTURE_DIRS', 'INSTALLED_APPS', 'LANGUAGES',
'LANGUAGE_CODE', 'LOCALE_PATHS', 'LOGIN_REDIRECT_URL', 'LOGIN_URL',
'LOGOUT_REDIRECT_URL', 'MEDIA_ROOT', 'MEDIA_URL', 'MIDDLEWARE', 'ROOT_URLCONF',
'SERIALIZATION_MODULES', 'STATIC_ROOT', 'STATIC_URL', 'TEMPLATES', 'USE_TZ']

Note that Lino writes to your settings module's global namespace only while the Site class gets instantiated. So if for some reason you want to modify one of the settings, do it after your SITE=Site(globals()) line.

Additional local apps

An optional second positional argument can be specified by the site maintainer in order to specify additional local plugins. These will go into the INSTALLED_APPS setting, together with any other plugins needed by them.

>>> from lino_book.projects.min9.settings import Site
>>> pseudoglobals = {}
>>> Site(pseudoglobals, "lino_xl.lib.events")  
<lino_book.projects.min9.settings.Site object at ...>
>>> print('\n'.join(pseudoglobals['INSTALLED_APPS']))
... 
lino
lino.modlib.about
lino.modlib.jinja
lino.modlib.bootstrap3
lino.modlib.extjs
lino.modlib.printing
lino.modlib.system
lino.modlib.help
lino.modlib.office
lino_xl.lib.xl
lino_xl.lib.countries
lino_book.projects.min9.modlib.contacts
django.contrib.contenttypes
lino.modlib.gfks
lino_xl.lib.excerpts
lino.modlib.users
lino.modlib.linod
lino.modlib.checkdata
lino_xl.lib.addresses
lino_xl.lib.phones
lino_xl.lib.cal
lino_xl.lib.reception
lino_xl.lib.courses
lino.modlib.weasyprint
lino.modlib.uploads
lino_xl.lib.ledger
lino_xl.lib.sepa
lino.modlib.memo
lino_xl.lib.notes
lino_xl.lib.humanlinks
lino_xl.lib.households
lino_xl.lib.calview
lino.modlib.publisher
lino_xl.lib.topics
lino_xl.lib.pages
lino.modlib.export_excel
lino_xl.lib.dupable_partners
lino.modlib.tinymce
lino_xl.lib.appypod
lino.modlib.notify
lino.modlib.changes
lino.modlib.comments
lino_xl.lib.properties
lino.modlib.languages
lino_xl.lib.cv
lino_cosi.lib.cosi
lino_xl.lib.b2c
lino_xl.lib.products
lino_xl.lib.vat
lino_xl.lib.trading
lino_xl.lib.finan
lino_xl.lib.shopping
django.contrib.staticfiles
lino_xl.lib.events
django.contrib.sessions

As an application developer you won't specify this argument, you should specify your installed plugins by overriding get_installed_plugins.

Besides this you can override any class argument using a keyword argment of same name:

  • lino.core.site.Site.title

  • lino.core.site.Site.verbose_name

You've maybe heard that it is not allowed to modify Django's settings once it has started. But there's nothing illegal with this here because this happens before Django has seen your settings.py.

Lino does more than this. It will for example read the __file__ attribute of this, to know where your settings.py is in the file system.

Technical details

Here are the Django settings that Lino will override:

>>> from lino.core.site import TestSite as Site
>>> SITE = Site()
>>> print([k for k in SITE.django_settings.keys() if k.isupper()])
... 
['SECRET_KEY', 'DATABASES', 'SERIALIZATION_MODULES', 'DEFAULT_AUTO_FIELD',
'LANGUAGES', 'INSTALLED_APPS', 'MEDIA_ROOT', 'ROOT_URLCONF', 'MEDIA_URL',
'STATIC_ROOT', 'STATIC_URL', 'USE_TZ', 'TEMPLATES', 'MIDDLEWARE',
'AUTHENTICATION_BACKENDS', 'LOGIN_URL', 'LOGIN_REDIRECT_URL',
'LOGOUT_REDIRECT_URL', 'FIXTURE_DIRS', 'LOCALE_PATHS']
>>> from pprint import pprint
>>> from atelier.utils import rmu
>>> pprint(rmu(SITE.django_settings))
... 
{'AUTHENTICATION_BACKENDS': ['lino.core.auth.backends.ModelBackend'],
 'DATABASES': {'default': {'ENGINE': 'django.db.backends.sqlite3',
                           'NAME': '.../core/default.db'}},
 'DEFAULT_AUTO_FIELD': 'django.db.models.BigAutoField',
 'FIXTURE_DIRS': (),
 'INSTALLED_APPS': ('lino',
                    'lino.modlib.about',
                    'lino.modlib.jinja',
                    'lino.modlib.bootstrap3',
                    'lino.modlib.extjs',
                    'django.contrib.staticfiles'),
 'LANGUAGES': [('en', 'English')],
 'LOCALE_PATHS': (),
 'LOGIN_REDIRECT_URL': '/',
 'LOGIN_URL': '/accounts/login/',
 'LOGOUT_REDIRECT_URL': None,
 'MEDIA_ROOT': '.../core/media',
 'MEDIA_URL': '/media/',
 'MIDDLEWARE': ('django.middleware.common.CommonMiddleware',
                'lino.core.auth.middleware.NoUserMiddleware',
                'lino.utils.ajax.AjaxExceptionResponse'),
 'ROOT_URLCONF': 'lino.core.urls',
 'SECRET_KEY': '20227',
 'SERIALIZATION_MODULES': {'py': 'lino.utils.dpy'},
 'STATIC_ROOT': '...static_root',
 'STATIC_URL': '/static/',
 'TEMPLATES': [{'APP_DIRS': True,
                'BACKEND': 'django.template.backends.django.DjangoTemplates',
                'DIRS': [],
                'OPTIONS': {'context_processors': ['django.template.context_processors.debug',
                                                   'django.template.context_processors.i18n',
                                                   'django.template.context_processors.media',
                                                   'django.template.context_processors.static',
                                                   'django.template.context_processors.tz',
                                                   'django.contrib.messages.context_processors.messages']}},
               {'BACKEND': 'django.template.backends.jinja2.Jinja2',
                'DIRS': [],
                'OPTIONS': {'environment': 'lino.modlib.jinja.get_environment'}}],
 'USE_TZ': False,
 '__file__': '.../lino/core/site.py...'}

Here are the Django settings that Lino does not modify:

>>> import lino_book.projects.lydia.settings.demo as settings
>>> print([s for s in dir(settings)
...     if not s in SITE.django_settings and s[0].isupper()])
... 
['ADMINS', 'ALLOWED_HOSTS', 'AUTH_USER_MODEL', 'DEBUG',
'DEBUG_PROPAGATE_EXCEPTIONS', 'EMAIL_HOST', 'LANGUAGE_CODE', 'MANAGERS',
'SETUP_INFO', 'SITE', 'Site', 'TEMPLATE_DEBUG', 'TEST_RUNNER', 'TIM2LINO_LOCAL',
'TIM2LINO_USERNAME', 'TIME_ZONE', 'USE_I18N']