How to install Django on Ubuntu 18.04?

Windows Articles

How to install Redis on CentOS 8?

Hello, friends in this post, we will show you how to install Redis on CentOS 8 As we well...

How to enable and disable startup applications in Windows 10

Hello! Windows 10 is an attractive and very easy to use system. However, some criticism has come for being too "heavy". That...

How to install Oracle Java 15 on Ubuntu 20.04 / 18.04?

Hello, friends. We know that Java is one of the most popular programming languages and now it's version 15. So in this...

How to run the Linux Tail command in Windows 10.

Hi! The title of this post may seem incongruous, but it's not. In fact, for some time Microsoft has approached positions with...

How to compress large videos in Windows 10

Hello, how are you? Multimedia resources are definitely used in any system. Indeed, we live in the age of technology. That's why...
angeloma
angeloma
Senior Writer and partner

As you know, web development is becoming more and more important among programmers. Just recognize that many services require the cloud to work. For this reason, many developers are more and more interested in making applications with cutting-edge technologies for their applications. So, today, I will show you how to install Django in Ubuntu 18.04.

Django is a framework for web development that uses Python as the programming language. It is very popular because it can make sites and web applications of high complexity with reasonable times and works very well with high user traffic.

So, let’s do it.

Install Django on Ubuntu 18.04

Actually, there are three different ways to install Django. This is due to the flexibility of Python as a programming language.

  1. You can install Django using pip.
  2. The second way is, install Django using Virtualenv.
  3. And the third option is to download it from the git repository.

In this tutorial, I will use the second option. So let’s get to work.

First, you need to know what is Virtualenv. Virtualenv is an application that allows you to create multiple virtual environments in Python. Each virtual environment can have its own version of the interpreter and separate configurations.

So, install it using pip.

:~$ sudo apt install python3-pip

1.- Installing python pip
1.- Installing python pip

Check the pip version installed.

:~$ pip3 --version

2.- checking the installed version
2.- checking the installed version

Next, install Virtualenv.

:~$ sudo apt install virtualenv python3-virtualenv

3.- Installling virtualenv
3.- Installing virtualenv

So, the next step is to create a new environment with Python3 by default called example.

:~$ virtualenv --python=python3 example

4.- Creating a new virtual environment
4.- Creating a new virtual environment

Then, activate the new virtual environment.

:~$ cd example
:~$ source bin/activate

Next, install Django.

:~$ pip install django==2.1.4

5.- Install Django
5.- Install Django

Note: At the time of writing this post, the latest stable version of Django is 2.1.4

So, check the installation.

:~$ django-admin --version

6.- Check the installation
6.- Check the installation

So, let’s create a Django project.

Create a new project

A recommended way to do projects with Django is to create a new virtual environment for each one.

In this case, I will continue with the one I just created. All that remains is to create the project itself.

:~$ django-admin startproject newproject

7.- Creating a new project
7.- Creating a new project

Explore the project folder.

:~$ cd newproject
:~$ tree

8.- Exploring the project folder
8.- Exploring the project folder

Edit settings.py file. In the Allowed hosts section add your IP.

:~$ nano newproject/settings.py

9.- Setting the allowed hosts
9.- Setting the allowed hosts

Now it’s time to raise the project with Django runserver.

:~$ python manage.py runserver 192.168.1.36:8000

10.- Starting the project
10.- Starting the project

Open your web browser and go to http://your_IP:8000. You will see the Django default page. In short, Django is correctly installed.

11.- Django correctly installed
11.- Django correctly installed

If you want to stop the project, press CTRL + c.

Just create the administrator account for Django. To do this, type the following.

:~$ python manage.py migrate

12.- Running the Django migrations
12.- Running the Django migrations

Django will automatically create the database for the administrator account, however, it is necessary to execute and do the migrations.

Now create the admin account. You will have to set a username and password.

:~$ python manage.py createsuperuser

13.- creating the admin account
13.- creating the admin account

Run Django runserver again and access the administration panel.

:~$ python manage.py runserver 192.168.1.36:8000

Now, open your web browser and go to http://your_ip:8000/admin. And you will see this:

14.- Django administration
14.- Django administration

Type your credentials. Next, click on Log in.

15.- Django administration panel
15.- Django administration panel

And that’s it.

Conclusion

Django is a framework written in python that is very popular and powerful. There are many popular sites that use it because of its tolerance to high levels of traffic. In addition, it stands out for its security policies.

Please share this post.

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

How to install Redis on CentOS 8?

Hello, friends in this post, we will show you how to install Redis on CentOS 8 As we well...

How to enable and disable startup applications in Windows 10

Hello! Windows 10 is an attractive and very easy to use system. However, some criticism has come for being too "heavy". That...

How to install Oracle Java 15 on Ubuntu 20.04 / 18.04?

Hello, friends. We know that Java is one of the most popular programming languages and now it's version 15. So in this...

How to run the Linux Tail command in Windows 10.

Hi! The title of this post may seem incongruous, but it's not. In fact, for some time Microsoft has approached positions with...

How to compress large videos in Windows 10

Hello, how are you? Multimedia resources are definitely used in any system. Indeed, we live in the age of technology. That's why...
x