Setting up a Virtual Development Environment for Django3

Setup Django venv

Goal: A Professional Quality Development Environment

If you already have Django 3.x installed in your system, then you can skip this post but if it's not, then don't worry we will get everything up and running in the next few minutes.
To install django, you need to have Python 3.x running in your System. To install python in your system, you can check official website of python
To confirm whether you have python installed in your system or not, just type python in your shell and you should see the shell of python3.8.x

Creating an isolated Python environment

After you have Python3.x running in your system, We will now create a virtual environment which won't have anything installed except the python and we will use this to work on our django projects. Using virtual environments helps us to separate different package versions for different projects. Also if you are in multi user OS, then you won't need any permissions to install anything and work on your project. So let's start creating our environment :-

  1. Run the command - python -m venv djangoenv - where djangoenv is the name of your virtual environment and that's it your virtual environment is created. You should see a directory with the name djangoenv which will have all the libraries you install in this env.
  2. Now we need to Activate our djangoenv, To activate, run the command - source djangoenv/bin/actiavte and you should see (djangoenv) in your command prompt or terminal.

  3. Screenshot showing djangoenv
  4. If you want to deactivate your venv at anytime, just run - deactivate in your terminal

What other's are reading :-

-->> Let's Start with the Basics of HTML
-->> Getting Started with Android App Development With Kotlin

Installing Django with pip

Now when we have python venv setup in our system, let's install Django3 in our virtual environment. For this, Run the command - pip install "django==3.0.*"
After you run this command, if you want to confirm that django is installed in your venv or not, just run the command - django-admin version and it should give you output '3.0.x'

Screenshot of django-admin version

Perfection is impossible

This may happen that you may already have some previous versions of those discussed above and it is recommended that you should install the latest versions for better results and learning, for that, upgrade your python and django whenever possible to latest versions. Also, while installing python, django or setting up the environment you may face many issues and that's okay, it is a part of developer life. We developers learn through the errors and learning by solving errors has been accepted as the best way of learning. Research on the errors you get and try to find their solutions through google or youtube. If the error isn't resolved even after that, you can comment below, I will be happy to help.

Take Detailed Notes

Maintain text files based on topics in a directory where you can keep notes of the commands and things we will do in the code and their working for future reference because we tend to forget some part always and these notes will help you there. If you are using a Linux system then it will be easy to find what you are looking for if available in any text file in the directory by running the command - grep -irn "text you are looking for" and it will find the text for you available in any file with their line numbers where the text is present so it will save a lot of time of yours.

Install Visual Studio Code

Visual Studio Code normally known as VSCode is an Open Source IDE (Integrated Development Environment) by Microsoft and according to the Developer Survey 2019 by Stackoverflow it is the most popular developer environment tool in the world. The reasons for VSCode being the most popular IDE are:

  1. It is Open Source
  2. It has built-in Source Code Management
  3. It has huge number of extensions which makes it easy to work on almost any technology in the world

If you already have VSCode installed in your system, then you can skip this step and If you haven't follow along the steps given below:

  1. Go to VSCode Download Page.
  2. Click on the Download button for whichever platform you are using.
  3. After Downloading, Double-click the file in your OS and Accept default settings.
  4. Follow the instructions on the screen
  5. Finish the Installation and Relax

Summary

Now that we have setup everything needed to work on our django project, we will start with our first project in the next post. Setting up environment may take time but once you setup environment for any technology on which you want to work, it becomes easy for you as you won't have to worry about anything else and you can focus on your code and the project. If you face any difficulty in setting up environment, try to resolve it on your own first and if you are not able to do it still, comment below. Also, if you have any feedbacks or suggestion I would love to hear them in the comments. Don't forget to share the post with your mates if you learnt something from it.

Comments

Popular posts from this blog

Redhat Ansible Expert Session Self Reflection

Introduction to Creating Web Apps by using Python-Django Framework