Welcome | Get started | Dive into Lino | Contribute | Reference | More
Create your first Lino site¶
Create your first Lino site¶
Run getlino startsite
to create a first site:
$ getlino startsite noi first
You may replace the name noi
in above command by other names.
The available choices are listed in List of known Lino applications.
Run runserver
:
$ go first # alias for: cd ~/lino/lino_local/first
$ python manage.py runserver
Now start your browser, point it to http://127.0.0.1:8000/ and you should see something like this:

Congratulations! Enjoy the first Lino site running on your machine!
Did you notice?¶
- ~/lino/lino_local¶
This is your projects root, the directory that will hold all the Lino sites
on your computer. Every new Lino site created with getlino startsite
will be a directory below this one.
- ~/lino/lino_local/first¶
This is the Django project directory of the first site you just created. Usually there is one Django project directory for every Lino site. (An exception to that rule is a site with multiple front ends, you may leave this for later).
Lino project directories are not very big, and you will hopefully create many such projects and want to keep a backup of them.
Let's have a look at the files in ~/lino/lino_local/first
.
The settings.py
file¶
Your first settings.py
file should look as follows:
# -*- coding: UTF-8 -*-
from lino_noi.lib.noi.settings import *
from lino_local.settings import *
class Site(Site):
title = "first"
server_url = "http://localhost"
languages = 'en'
# use_linod = True
default_ui = 'lino_react.react'
show_internal_field_names = True
def get_plugin_configs(self):
yield super().get_plugin_configs()
# example of local plugin settings:
# yield ('ledger', 'start_year', 2018)
yield ('help', 'make_help_pages', True)
SITE = Site(globals())
DEBUG = True
# ALLOWED_HOSTS = ['localhost']
SECRET_KEY = '7SPXrSWRJq7hgm4LOhoKP3mHFcM'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'first',}
}
EMAIL_SUBJECT_PREFIX = '[first] '
Explanations:
It imports the settings from
lino_noi.lib.noi.settings
because you saidnoi
as the application for our first site. It imports them directly into your global namespace using the wildcard*
. Yes, you want them to become our Django settings.It then does the same with the
lino_local.settings
. This module has been created bygetlino configure
, its source code is in~/lino/lino_local/settings.py
, and it contains Django settings that are likely to be the same for all Lino sites on a same server. For exampleADMINS
,EMAIL_HOST
orSERVER_EMAIL
Then you redefine the
Site
class using local settings.Then comes the trick that turns your Django project into a Lino application:
SITE = Site(globals(), ...)
That is, you instantiate a
Site
class and store this object asSITE
in your Django settings. This line will automatically install default values for all required Django settings (e.g.DATABASES
andLOGGING
) into your global namespace.
You might add DEBUG = True
or other settings of your choice
after these two lines.
There are two possibilities to override the Site
attributes. The most
basic way is:
from lino_noi.lib.noi.settings import *
SITE = Site(globals(), title="My Lino site", is_demo_site=False, languages="en fr")
DEBUG = True
The more explicit way is this:
from lino_book.projects.chatter.settings import *
class Site(Site):
title = "My Lino site"
is_demo_site = False
languages = "en fr"
SITE = Site(globals())
DEBUG = True
This way is recommended because it allows to override methods as well. Yes,
Lino saves us not only from having to define all-uppercase settings, it also
adds the full power of the Python language to your settings.py
file.
More about this in The local settings.py file.
The manage.py
file¶
The manage.py
file should have the following content:
#!/usr/bin/env python
import os
import sys
sys.path.insert(0, '/home/joe/lino')
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lino_local.first.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
A manage.py
file does two things: it sets the
DJANGO_SETTINGS_MODULE
environment variable and then calls Django's
execute_from_command_line
function.
Loading initial data into your database¶
Next we create your database and populate it with some demo content. With a Lino application this is easier than with a plain Django project, it is just one command to type:
$ python manage.py prep
The pm prep
command is a custom django-admin
command
provided by Lino. It is just a thin wrapper that calls pm initdb
with
a default list of fixtures to load. It will ask you:
INFO Started manage.py prep (using settings) --> PID 28463
We are going to flush your database (.../default.db).
Are you sure (y/n) ?
If you answer "y" here, then Lino will delete everything in the given
database and replace it with its "factory default" demo data. Yes,
that's what we want. So go on and type y
.
The output that follows should look like this:
`initdb std demo demo2` started on database ...docs/dev/hello/default.db.
...
Installed 291 object(s) from 10 fixture(s)
Lino applications make abundant use of what we call Python fixtures in order to have a rich set of "demo data".
The default list of fixtures to be used by pm prep
is defined by the
application developer in the Demo fixtures attribute.
Visualizing database content from the command-line¶
The runserver
command starts a web server and lets you
interact with the database through the web interface. But Django also
offers a shell
interface.
We will come back to this later, for the moment just try the following.
You can visualize the content of your database from the command-line
without starting a web server using Lino's show
command.
For example to see the list of countries, you can write:
$ python manage.py show countries.Countries
This will produce the following output:
============================= ==========
Designation ISO code
----------------------------- ----------
Bangladesh BD
Belgium BE
Congo (Democratic Republic) CD
Estonia EE
France FR
Germany DE
Maroc MA
Netherlands NL
Russia RU
============================= ==========
Exercises¶
You can now play around by changing things in your project.
In your
settings.py
file, replacelino_noi.lib.noi.settings
bylino_book.projects.polly.settings
. Runpm prep
followed bypm runserver
. Log in and play around.Same as previous, but with
lino_book.projects.chatter
Find and have a look at the source code of the
lino_noi.lib.noi.settings
file. Saypywhich lino_noi
to get a hint where this source code is stored.
Read the documentation about the following Site attributes and try to change them:
Checkpoint¶
If you follow an internship, you should now have a meeting with your mentor and show him what you learned so far. You'll get a badge to certify your progress.
Glossary¶
- Django project directory¶
A directory that contains a runnable Django project. It contains the files necessary for that specific instance of a given Lino application.