In this tutorial, we’ll be showing you how to install Django on your Debian Cloud VPS.
There is a very good reason why Django is the top Python web development framework. It is powerful, flexible, and at the same time, it does not get in the developers’ way. It scales very well too, powering sites such as Instagram.
apt, which can be considered as the more user-friendly method. In this tutorial, however, we’ll be covering both methods. Let’s get started with the installation.
Available Installation Methods
Depending upon your needs and the manner you want to configure your development environment, there are several ways in which you can install Django. If you need more independent Django installs or you want to work with Python versions which are different than the ones used by Debian by default, then the virtualenv route is the best way to go. Let’s show you how to do that now.
Method 1: The Virtualenv Way
Step 1. Installing the Packages
For starters, you have to make sure that the Python is installed and then install the
virtualenv package to compartmentalize your Python projects.
# apt install python python3 virtualenv
Step 2. Setting Up Virtualenv
You can use virtualenv in order to create a new virtual environment for the Python project after the installation of the packages has finished.
$ virtualenv -p python3 django-project
With the command above, you will prompt virtualenv to create a new virtual environment using the current Python 3 version which is installed on the system. If the
-p python3 part is left off, then the current system default will be used by virtualenv, which is version 2.7 on Debian Stretch.
In order to use the new virtual environment,
cd into the folder and activate it.
# cd django-project # source bin/activate
At the beginning of your prompt, you will be able to see the folder’s name in parenthesis. After you finish using the virtual environment, then you can exit by typing
Method 2: The Debian Way
Another way of doing things that usually works well is the Debian way. If you are more into a system-wide Django install, then you should definitely use the packaged version of Django, which is available from Debian’s repositories.
Step 1. Installing the Packages
This way of installing Django is quite simple. All you need to do is to install the packages.
# apt install python python3 python-django
Setting Up Django
At this point when your virtual environment has been set up and activated, Django can be installed. Virtualenv will automatically add the Python package manager
pip to each environment that gets created. This Python package manager acts just like other package managers – it handles installs, removals, and updates. Due to the fact that you are using virtualenv, the packages that pip manages are specific to that one environment.
You can use pip to install Django just by telling it to install.
# pip install django
Pip will handle dependency management and pull in Django. Once again, don`t forget that it only applies to that environment.
If you are interested in creating your new project, in that case you can use Django’s built-in utilities.
# django-admin.py startproject yoursite
The base project files will be created by Django and they will have a name which is specified by you. At this point you are able to
cd into your new Django project. While you’re there, don’t forget to set up the database. You can do that by applying the basic migrations and creating your user.
# cd yoursite # python manage.py migrate # python manage.py createsuperuser
You will have to enter the information for your site’s admin user. You can fill it out as you like.
You will be asked to enter the information for your site’s admin user. Fill it out however you’d like. This information will be entered into the development database, so it’s not such a big deal, unless you plan to import it into your production one.
Now your new Django project can be tested. In order to start up the development server use
manage.py one more time.
# python manage.py runserver
You can use
localhost:8000 to view the static start page in your browser. That’s it! You have successfully installed and set up Django on your Debian 9 Cloud VPS.
Of course, you don’t have to Install Django on Debian 9 if you use one of our Django Cloud VPS Hosting services, in which case you can simply ask our expert Linux admins to install Django on your Debian VPS for you. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post on how to install Django on Debian 9, please share it with your friends on the social networks using the buttons below or simply leave a reply in the comments sections. Thanks.