Django 3.0.4

Create a virtual environment, activate it and install django in it:

(search) [user]@[machine]:~$ pip install django
Collecting django
  Downloading Django-3.0.4-py3-none-any.whl (7.5 MB)
     |████████████████████████████████| 7.5 MB 3.3 MB/s 
Collecting asgiref~=3.2
  Downloading asgiref-3.2.7-py2.py3-none-any.whl (19 kB)
Collecting sqlparse>=0.2.2
  Downloading sqlparse-0.3.1-py2.py3-none-any.whl (40 kB)
     |████████████████████████████████| 40 kB 934 kB/s 
Collecting pytz
  Downloading pytz-2019.3-py2.py3-none-any.whl (509 kB)
     |████████████████████████████████| 509 kB 2.9 MB/s 
Installing collected packages: asgiref, sqlparse, pytz, django
Successfully installed asgiref-3.2.7 django-3.0.4 pytz-2019.3 sqlparse-0.3.1

If you get errors like The script sqlformat is installed in '/home/<user>/.local/bin' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use –no-warn-script-location., make sure you have export PATH=$PATH:$HOME/.local/bin in your .bashrc, bash_profile or .profile and either source the changed file or re-login.

(search) [user]@[machine]:$ django-admin startproject search

This creates a basic django structure:

(search) [user]@[machine]:~/search$ tree
.
├── manage.py
└── search
    ├── asgi.py
    ├── __init__.py
    ├── settings.py
    ├── urls.py
    └── wsgi.py

1 directory, 6 files

Test it works. We are using the Django development server, not to be used in production environments. There are no database tables yet, so expect warnings …

(search) [user]@[machine]:~/search $ python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.

March 13, 2020 - 00:06:49
Django version 3.0.4, using settings 'Search.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Create SQLite database (db.sqlite3) and the tables for authentication:

(search) [user]@[machine]:~/search$ python manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying sessions.0001_initial... OK

Test again:

(search) [user]@[machine]:~/search $ python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
March 13, 2020 - 00:13:23
Django version 3.0.4, using settings 'Search.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

And point browser to http://localhost:8000, and if all is well, it looks like:

Create superuser account

http://localhost:8000/admin looks like:

Create the superuser (account with full privileges, email address can be left blank, but provide a valid-secure password to avoid being warned about password security)

(search) [user]@[machine]:~/search$ python manage.py createsuperuser
Username (leave blank to use '<user>'): xxxxx
Email address: 
Password: 
Password (again): 
Superuser created successfully.

And these can be used to login on the Django localhost admin page.

(search) [user]@[machine]:~/search$ python manage.py startapp collection
(search) [user]@[machine]:~/search$ tree
.
├── collection
│   ├── admin.py
│   ├── apps.py
│   ├── __init__.py
│   ├── migrations
│   │   └── __init__.py
│   ├── models.py
│   ├── tests.py
│   └── views.py
├── db.sqlite3
├── manage.py
└── search
    ├── asgi.py
    ├── __init__.py
    ├── __pycache__
    │   ├── __init__.cpython-37.pyc
    │   ├── settings.cpython-37.pyc
    │   ├── urls.cpython-37.pyc
    │   └── wsgi.cpython-37.pyc
    ├── settings.py
    ├── urls.py
    └── wsgi.py

4 directories, 18 files
  • Last modified: 2020/03/26 20:21