Welcome | Get started | Dive | Contribute | Topics | Reference | Changes | More
Create your first Lino site¶
Create your first Lino site¶
(1) Run getlino startsite
to create a first site:
$ getlino startsite polly first
(2) The first argument (“polly”) is the nickname of the application to
install. Run getlino list
to get a list of available choices.
(3) The second argument (“first”) is the nickname you give to your Lino site.
(4) Run runserver
:
$ go first
$ runserver
(5) Start your browser and point it to http://127.0.0.1:8000/
You should see something like the image in Install your Lino developer environment.
(6) It looks the same because it is the same application (Polly), but the files are organized differently. This is no longer a demo project, it is the first Lino site running on your machine.
File locations¶
- ~/lino/lino_local¶
(7) This is your projects root, the base directory for every
project of which you are the author. Every new Lino site created with
getlino startsite
will be a directory below this one.
- ~/lino/lino_local/first¶
(8) This directory contains the first site you just created. It is a Django project directory.
- 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.
(9) Usually there is one Django project directory for every Lino site.
(10) Lino project directories aren’t very big, and you will hopefully create many such projects and want to keep a backup of them.
(11) Note that first
has automatically become a nickname. also
inspects your local Lino sites. You can now say go first
in order to
change to that directory.
(12) Let’s have a look at the files in ~/lino/lino_local/first
.
The settings.py
file¶
(13) Your first settings.py
file should look as follows:
# -*- coding: UTF-8 -*-
from lino_book.projects.polly.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 ('periods', '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:
(14) 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.(15) 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
(16) Then you redefine the
Site
class using local settings.(17) 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.
(18) You might add DEBUG = True
or other settings of your choice
after these two lines.
(19) More about the settings.py
file in The local settings.py file.
The manage.py
file¶
(20) 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)
(21) 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.
Visualizing database content from the command-line¶
(22) 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.
(23) 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 polls.Polls
(24) This will produce the following output:
=========== ============================== ============ ========
Reference Heading Author State
----------- ------------------------------ ------------ --------
Customer Satisfaction Survey Robin Rood Active
Participant feedback Robin Rood Active
Political compass Robin Rood Active
=========== ============================== ============ ========
Exercises¶
(25) You can now play around by changing things in your project.
(26) In your settings.py
file, replace
lino_book.projects.polly.settings
by lino_noi.lib.noi.settings
.
Run pm prep
followed by pm runserver
. Log in and play around.
(27) Same as previous, but with lino_book.projects.chatter
(28) Technically speaking, Polly, Noi and Chatter are different Lino applications. What does Polly do? And what does Chatter do?
(29) Find the source code of the lino_noi.lib.noi.settings
file.
Say pywhich lino_noi
to get a hint where this source code is stored.
(30) Read the documentation about the following Site attributes and try to change them:
Checkpoint¶
(31) 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.