Django is a free and open-source high-level Python web framework designed to help developers build secure, scalable and maintainable web applications.
There are different methods to install Django, depending on your needs. It can be installed system-wide or in a Python virtual environment using pip.
Django packages are also included in the official Ubuntu repositories and can be installed using the apt package manager. This is the easiest method to install Django on Ubuntu 18.04, but not as flexible as installing in a virtual environment. Also, the version included in the repositories always lags behind the latest version of Django.
The main purpose of Python virtual environments is to create an isolated environment for different Python projects. This way you can have multiple different Django environments on a single computer and install a specific version of a module on a per project basis without worrying that it will affect your other Django installations. If you install Django into the global environment then you can install only one Django version on your computer.
The following sections provide a step by step instructions about how to install Django in a Python virtual environment on Ubuntu 18.04.
Ubuntu 18.04 ships with Python 3.6 by default. You can verify that Python 3 is installed on your system by typing:
The output should look like this:
Starting from Python 3.6, the recommended way to create a virtual environment is to use the
venv module. To install the
python3-venv package that provides the
venv module run the following command:
sudo apt install python3-venv
Once the module is installed we are ready to create a virtual environment for our Django application.
Start by navigating to the directory where you would like to store your Python 3 virtual environments. It can be your home directory or any other directory where your user has read and write permissions.
Create a new directory for your Django application and navigate into it:
mkdir my_django_app cd my_django_app
Once inside the directory, run the following command to create your new virtual environment:
python3 -m venv venv
The command above creates a directory called
venv, which contains a copy of the Python binary, the Pip package manager , the standard Python library and other supporting files. You can use any name you want for the virtual environment.
To start using this virtual environment, you need to activate it by running the
Once activated, the virtual environment’s bin directory will be added at the beginning of the
$PATH variable. Also your shell’s prompt will change and it will show the name of the virtual environment you’re currently using. In our case that is
Now that the virtual environment is activated, you can use the Python package manager pip to install Django:
pip install django
To verify the installation use the following command which will print the Django version:
python -m django --version
At the time of writing this article, the latest official Django version is 2.1.2
Your Django version may differ from the version shown here.
i hope you like this small article
How to Create CSV file in Python 3In this article, I will share with you h...
How to Convert JS Object to JSON StringUse the JSON.stringify() Method You c...
Angular9 - Routing And Navigation Example1. Introduction to Angular 7|8|9 Routing...
Laravel 8 - How to send Bulk Mail in Background using QueueIn this article, i will share with you h...