How to install Django on Ubuntu 18.04?

0
162
django

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.

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

Check the pip version installed.

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

Next, install Virtualenv.

3.- Installling virtualenv
3.- Installing virtualenv

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

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

Then, activate the new virtual environment.

Next, install Django.

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.

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.

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

Explore the project folder.

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

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

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

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

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.

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.

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

Run Django runserver again and access the administration panel.

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.

Spread the love
  • 5
    Shares

PS. If you like this post please share it with your friends on the social networks using the buttons above.Thanks.

LEAVE A REPLY

Please enter your comment!
Please enter your name here