location
  English
Phone:  +1 (217) 636-4164
Skype:  onegbits
  1. Home
  2. Blog
  3. How to Install Django on Ubuntu 16.04 - Django Tutorial

How to Install Django on Ubuntu 16.04 - Django Tutorial

01

Oct, 16

38

How to Install Django on Ubuntu 16.04 How to Install Django? Django is a powerful Python Web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. It’s free and open source. In this article, we will be using Python version 3 for Django as recommended from the official Django site. To install python3-pip from the Ubuntu repository, use the following command-
$ sudo apt-get install python3-pip
To create a symlink for PIP3 to PIP, use the following commands –
$ which pip3
$ ln -s /usr/bin/pip3 /usr/bin/pip
Now verify the version of PIP using the following command –
$ pip -V
The sample output should be like this –
pip 1.5.6 from /usr/lib/python3/dist-packages (python 3.4)

Installing Django with PIP

To install Django with pip, use the following command –
$ sudo pip install django
The sample output should be like this –
Collecting django
  Downloading Django-1.9.6-py2.py3-none-any.whl (6.6MB)
    100% |████████████████████████████████| 6.6MB 179kB/s 
Installing collected packages: django
Successfully installed django-1.9.6
To install Django-admin, use the following command –
$ sudo apt install python-django-common
The sample output should be like this –
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  apport-hooks-elementary contractor libgda-5.0-4 libgda-5.0-common
  libgranite-common libgranite3 libgsignon-glib1 libindicate5 libnoise-core0
  libtagc0 mysql-server-5.7 mysql-server-core-5.7
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
  python-django-common
0 upgraded, 1 newly installed, 0 to remove and 187 not upgraded.
Need to get 1,182 kB of archives.
After this operation, 14.6 MB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu xenial/main amd64 python-django-common all 1.8.7-1ubuntu5 [1,182 kB]
.................................................................................................
When the installation is done, check the Django version with the following command-
# django-admin --version
The sample output should be like this-
1.9.6

Creating a New Project

To create a new project called ‘myblog’ with the django-admin, use the following command –
# django-admin startproject myblog
Now enter into the project using CD command as shown below –
# cd myblog/
Now run the ‘manage.py’ file as shown below –
~/myblog# python manage.py runserver
The sample output should be like this –
May 17, 2016 - 05:07:05
Django version 1.9.6, using settings 'myblog.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Now, open any favorite browser and enter the server URL. In our case it is http://127.0.0.1:8000. the sample output should be like this – How to Install Django on Ubuntu 16.04 Now we will configure “Django admin”, wherein Django will automatically generate a database for a superuser. But before we create a superuser, run the following command –
$ python manage.py migrate
The sample output should be like this –
 Rendering model states... DONE
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... 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 sessions.0001_initial... OK
Now create the admin user as shown below –
$ python manage.py createsuperuser
The sample output should be like this –
Username (leave blank to use 'root'): tutorialspoint
Email address: [email protected]
Password: 
Password (again): 
Superuser created successfully.
The Django super user has been added, now you can use the runserver command to start Django admin. Open the browser and visit the Django admin page as shown below –
# python manage.py runserver
Open your browser and run server link, in this case, it should be like this –
http://127.0.0.1:8000/admin
The sample output should be like this – How to Install Django on Ubuntu 16.04 Enter your admin user name and password. Now the sample output should be like this – Django Tutorial That’s it. After this article, you will be able to understand – How to Install Django 1.9 on Ubuntu, we will come up with more Linux based tricks and tips. Keep reading!

In this article you have learned How to Install Django. follow up our blog for future posts.

Leave A Comment
We are with you

24 X 7 X 365

+1 (217) 636-4164

©2017 1Gbits. All rights reserved