DJANGO FRAMEWORK INSTALLATION AND CMS SETUP ON UBUNTU 18.04 LTS
Step 1
First and foremost we confirm the python version.
On my Ubuntu machine, there are two versions of python available, python 2.7 as default python version and python 3.
Check the python version:
python --version
So the default python is 2.7 at the moment.
Next, change the default python to python version 3 with the 'update-alternatives' command:
update-alternatives --install /usr/bin/python python /usr/bin/python3
Now confirm the python version.
And you will get python 3.* as a default python on the system. Setup Python 3 on Ubuntu
Note: By default, Ubuntu 18.04 has no 'python' command, because it brings the 'python3' command as default python. See the Bionic Beaver Release Notes.
Step 2
Let's Install Django, shall we?
Let's Install Django, shall we?
I'll take you through 3 ways to install Django. Please follow either chapter 2.1, 2.2 or 2.3 to install Django but not all 3 options at the same time :).
2.1. Install Django with Pip
Pip is a package management system for python. Python has a central package repository from which we can download the python package. It's called Python Package Index (PyPI).
In order to install Django with pip, we need to install 'python3-pip' package to the Ubuntu 18.04 system.
Run command below to install pip for python 3:
sudo apt install python3-pip -y
The installation will add a new binary file called 'pip3'. To make it easier to use pip, I will create a symlink for pip3 to pip:
$which pip3
ln -s /usr/bin/pip3 /usr/bin/pip
pip --version
The pip installation is done. Now we can use the pip command to install python packages. Let's install Django 2.0.5 stable version to the server with pip command below:
pip install Django==2.0.5
Note: We set the Django==2.0.5 to get a specific version. If you want a different version, just change the number e.g. to django==1.10 etc.
If you get an error about locale settings, run the following command to reconfigure the locale settings:
- export LANGUAGE=en_US.UTF-8
- export LANG=en_US.UTF-8
- export LC_ALL=en_US.UTF-8
- locale-gen en_US.UTF-8
- dpkg-reconfigure locales
After the installation is complete, check the Django version with the command below:
django-admin --version
You will see that Django 2.0.5 stable has been installed on the system.
2.2. Install Django with Virtualenv
Virtualenv is a python environment builder. It is used to create isolated python environments. We can choose the version of python that will be installed in the virtualenv environment. This is very useful for developers, they can run and develop an application with different python versions and different environments on one OS.
Virtualenv is available on PyPI repository - we can install it with the pip command:
pip install virtualenv
Now we can use the virtualenv command to create a new environment with python3 as default python version. So let's create a new environment "myenv01" with python3 as the python version and pip3 for the django installation.
virtualenv --python=python3 myenv01
The command will create a new directory called 'myenv01' which contains the directories bin, include and lib for python.
The virtualenv has been created, now let's log into the new environment with the following command:
cd myenv01/
source bin/activate
Next, install Django in the the virtual environment that we've created:
pip install django==2.0.5
When the installation finished, check the Django installation:
django-admin --version
When the installation is complete, create a new project called 'projectx1'(give it your name of choice) with the django-admin command:
django-admin startproject projectx1
The command will create a new directory 'projectx1' that contains Django files:
cd projectx1/
tree (you may need to install tree if you don't have it. sudo apt install tree)
Now edit the 'settings.py' under the 'projectx1' directory using vim/nano command.
nano projectx1/settings.py
Type the server IP address inside the 'ALLOWED_HOSTS' line as shown below.
ALLOWED_HOSTS = ['10.10.4.10']
or leave it blank [] to run as localhost.
Save and exit.
Now run the python django runserver command.
python manage.py runserver
or specify the IP address if you specified 127.0.0.1:8000
The command will run python django on the IP address '127.0.0.1', on port '8000'.
Django project started. Open your web browser and type the server IP address with port 8000.
http://127.0.0.1:8000
Press 'Ctrl+c' to exit from the django runserver.
2.3. Next, we will configure the Django admin.
Django will automatically generate the database for a superuser. Before we create the superuser, run the command below:
python manage.py migrate
migrate: make adds the models (adding fields, deleting etc.) into the database scheme, the default database is sqlite3.
Now create the admin/superuser:
python manage.py createsuperuser
Type your django admin user, email, and password.
Username (leave blank to use 'root'): django
Email address: admin@home-lab.io
Password:
Password (again):
Superuser created successfully.
The Django superuser has been created, now you can execute the runserver command, then go to the browser and visit the django admin page:
python manage.py runserver
Visit Django admin page: http://127.0.0.1:8000/admin/
Step 3 To install Django CMS
$ pip install --upgrade virtualenv
$ virtualenv myenv
$ cd myenv01/
$ source bin/activate
(myenv01) $ pip install djangocms-installer
(myenv01) $ djangocms alphasite01 (give it whatever name)
Finally
cd alphasite01/
Then run
python manage.py runserver
Now proceed to your browser http://127.0.0.1:8000/
VOILA!!!!!!
Comments
Post a Comment