Django, a free open source, Python web framework for developing dynamic apps and websites is easy to install in Ubuntu. This brief tutorial shows students and new users how to get Django web framework installed on Ubuntu 16.04 | 18.04 and 18.10.
If you’re a developer who is going to be developing apps in Python, it may be a good thing to use Django web framewrok to make the process seemless with rapid development and clean pragmatic design.
There are multiple ways to install Django on Ubuntu, however, the quickest way is go use Python and PIP to get is installed. Below, we’ll show you how to do that.When you’re ready to get Django on Ubuntu, follow the steps below:
Step 1: Install Prerequisites
By default, Ubuntu comes with some packages but not everthing that allows you to install Django web framework. For example, Pythong might not come standard with Ubuntu so you may have to install it. Run the commands below to install Pythong and Python-pip.
sudo apt update sudo apt-get install python3 python3-pip
That should install what you need to get Django installed on Ubuntu.
To verify what version of Python is installed, run the commands below
and for PIP, run the commands below
Step 2: Install Django
Now that the basic requirements to get Django on Ubuntu are installed, run the commands below to download and install Django packages.
Django has its source code on Github that you can use to download and use. however, the quickest way is to use Python PIP. Run the commands below to download and install Django using Python-Pip.
sudo pip3 install Django
That should get Django installed and ready to use.
To validate if Django is installed, run the commands below.
That will give you the version number of Django installed on your system.
Step 3: Create Django App
Now that Django is installed, go and create your first app environment. You can create it in your home directory or anywhere on the system. For this tutorial, we’re going to create the app in home directory.
cd ~/ django-admin startproject django_test cd django_test python3 manage.py migrate
That should setup Django environment. When you’re done, run the commands below to create Django super user account. this account will be used to access Django backend portal.
python3 manage.py createsuperuser
That should prompt you to create a superuser account.
Username (leave blank to use 'richard'): admin Email address: firstname.lastname@example.org Password: admin_password Password (again): admin_password Superuser created successfully.
When you’re done, run the commands below to start up and run Django server.
python3 manage.py runserver 0.0.0.0:8000
Now, open your browser and go to the server hostname or IP address followed by port 8000
You should see Django portal.
To go to the admin backend portal, type
That should prompt you for the superuser account and password. and allow you to logon to the backend.
Although that are many other settings you must configure to suit your environment, the steps above is the bare minimum to get Django installed.
To get external access to Django server, open its settings.py page and add the IPs
sudo nano ~/django_test/django_test/settings.py
Then add the IPs to the ALLOW_HOSTS line.
ALLOWED_HOSTS = [‘192.168.1.20‘, 220.127.116.11‘, . . .]
Save the file and exit.
You may also like the post below: