Django Environment Setup

Django is a free and open-source web framework, which uses Python as its programming language. It is based on Model View Template (MVT) architecture. A framework is a collection of all the applications needed for web development. It takes care of most of the basics of web development to don’t have to write code from scratch every time.

 It was first created in 2003 by two web programmers called Adrian Holovaty and Simon Willison. It was publicly released in 2005 under the BSD license.

The final version of Django was released in 2008, and a newly formed organization, Django Software Foundation, was announced to maintain Django in the future. 

Django's fundamental principles are scalability, re-usability, and rapid development. Django is also very popular for loose coupling, enabling every component to be independent of each other.

In this post, we will set up of developer environment for Django from the basic text editor to the layout of the application.

Text Editor

The text editor is the most basic part of any environment. It is the place where we write our code. It does not matter which text editor we use for the logic and actual computation, but we can get some great help from a good text editor. Notepad is also a text editor, but it does not provide anything like the auto-suggestion, the format for the file, etc. One of the most popular text editors in the modern era is Visual Studio Code. Visual Studio is free and easy to install. It provides many functionalities like a built-in terminal, auto-suggestion, and many more.

Installing Git

Git is an essential part of any software development. It is a version control system software. It is very useful in handling code for large projects. With Git, we can revert to previous versions of our code, share the code with other persons, collaborate with other developers, and track our work with the commits. We can download Git from this link: https://gitforwindows.org/ , click the download option, and then follow the installation process.

Command Line

Command Line is a very powerful tool for developers. Command-Line is used extensively throughout the development process. In windows, you can find it as Command Prompt. It is used in not only Django but in almost all kinds of projects and fields. As a developer, we should be aware of some basic commands on the command line.

  • Cd: Used to change directory.
  • Dir: It is used to list files in the current directory.
  • cd.. : This command takes you back to the previous directory
  • mkdir: Used to create a new directory.

Installing Python

The first step for setting up an environment for Django is to download Python. This is a programming language that is used by Django. To download Python go to the link https://www.python.org/downloads/and click on the download option. If you already have Python, you can check the version by using this command:

Python --version

After installing, to verify the installation, use this command:

Django Environment Setup

If this commands runs without an error, it means we have successfully installed Python. The next step is to install Django.

Before installing Django, we would like to create a virtual environment to store all our project files. Virtual Environments are very useful. They help to keep separate versions of a module for different projects without messing them up. To install the virtual environment, execute this command in your terminal or command prompt.

pip install virtualenv
Django Environment Setup

After creating the virtual environment, we want to create and activate this environment to use it. To create the virtual environment, go to the directory in which you want to create the environment and then type the command:

Virtualenvmyenv	

This will create a new directory named myenv in your current directory. To activate this virtual environment we just created, use the command below:

Myenv\Scripts\activate

If the environment is activated, we can see the environment name on the left side of the console.

Django Environment Setup

Django Installation

After successfully creating and activating the environment, the next step is to install Django. The easiest way to install Django is by using the python package pip. To install Django run this command in your command-line interface python –  m pip install Django.

Django Environment Setup

To verify if Django is correctly installed in your local machine or not, execute the following command in the Python console:

Import Django
Django Environment Setup

If this command does not show any error and Django is perfectly installed on your computer, we can check the version of the Django installed by running the below code in the python console.

Print(Django.get_version())

The above command will print the version number of Django.

To start creating the project, go to the directory where you want to create your project and run the following command in your command prompt.

django-adminstartprojectmyproject

This will create a project folder in which you can create the files for your apps.  The structure of this directory is:

  • manage.py
  • My project folder
    • __init__.py
    • Settings.py
    • Urls.py
    • Wsgi.py
    • Asgi.py

Now our project is ready to start the development server navigate to the project directory by cd myproject.

python manage.py runserver

The output of this command will be something like this in the terminal:

Performing system checks...
0 errors found
January 08, 2020 - 15:50:53
Django version 1.8, using settings 'myproject.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C

This output confirms that we have done our first project successfully and have started the development server. Go to the above URL to see the default homepage.

Django Environment Setup

Related Topics

Django Template System

Django Template System Django allows Python and HTML to be divided, the Python goes into views, and HTML goes into templates. Django relies on the render feature and the language of the Django Model...

5 minutes read.

Django Celery

Django is a python-based web framework. It is an open-source and free-to-use framework. Django uses the Model View Template architecture. Django provides many functionalities to web developers. One of these...

3 minutes read.

Django DRF

Django Rest Framework, which is also referred to as DRF, is a very powerful application to build RESTful APIs in a Django application. DRF uses the Django framework. Similar to...

3 minutes read.

Django Forms

Django is a Python Programming Open Source framework for web development. It was released in 2008 and was developed by two web developers named Adrian Holovaty and Simon Willison. It...

3 minutes read.

Django Authentication

Django is an open-source free to use web framework which is based on Python. Django uses Model-View-Template as its architecture. The final version of Django was released in 2008. Django...

4 minutes read.

Django Create Project

Django is an open-source free to use web framework which is based on Python. Django uses Model-View-Template as its architecture. The final version of Django was released in 2008. Django...

4 minutes read.

Django Frontend

Django Django is a framework that can make web applications more accessible and faster. Django is an open-source collection of python libraries, and Django can be used for both the front...

3 minutes read.

Django Stack

Django is a popular Python web application framework that adheres to the "batteries-included" tenet. Batteries-guiding included idea is that common functionality for creating web applications should be provided with the...

5 minutes read.

Django Logging

Every application developed has some bugs and errors. It is the responsibility of the developers to maintain the application by making it bug-free and error-free. To debug the application code...

5 minutes read.

Django Admin

To manage the content of the website, e.g., adding and deleting posts, web developers need an admin portal on the website. The admin portal allows trusted users, also knows as...

3 minutes read.

Django Create Superuser

For managing the website, we need an Admin while creating the Django application. In order to create the admin user, create superuser command is used. The superuser is called the...

3 minutes read.

Django CMS

Django is one of the most popular open-source Python web development framework. Developers use Django to build a website from scratch. Like WordPress, Django CMS is also a Content Management...

9 minutes read.

Features of Django

Features of Django Offers High Security:- Django is super secure. To prove the feature, we can always take examples of lots of websites which are present worldwide and possess huge traffic. Django is secure because it covers the...

3 minutes read.

Django Channels

Channels is a project that uses Django and adds some functionalities beyond the traditional HTTP by using WSGI and ASGI.  We can use both synchronous and asynchronous requests with ASGI...

5 minutes read.

Django Filters

Django is a high-level python based web framework. Django is mostly used as a backend engine for websites. Nowadays, every website communicates to a database to fetch all the information...

3 minutes read.

Django Installation

Django Installation Django development environment consists of installing and setting up Python, Django, and a Database System since Django deals with a web application. Below the statement will guide you through installing Python 3.8.0 and...

2 minutes read.

Django – Sending E-mails

Django – Sending E-mails Django comes with a light engine that is ready and simple to use to send emails. Similar to Python, you just need to import a smtplib. You just need to import django.core.mail in Django. Edit the project settings.py file to start sending emails and set  all the following options: EMAIL_HOST – server with smtp.EMAIL_HOST_USER – smtp server login key.EMAIL_HOST_PASSWORD ? Password credential for the smtp server.EMAIL_PORT – server port smtp.EMAIL_USE_TLS or _SSL – if it is secure connection then set True. Simple E-mail Sending To submit a simple e-mail, let's create it a "simpleEmail" view. from django.core.mail import...

3 minutes read.

Django ORM

Django is a Python web framework that enables easy and quick web development. Django has a handy and powerful feature called Django Object Relational Mapper, also known as Django ORM,...

3 minutes read.

What is Django?

What is Django? Django is a free and open-source web application framework, written in Python. A web framework is a set of components that help you develop an easier and faster website. When we...

3 minutes read.

Django All Auth

For any web application, user registration and authentication are the essential parts. In Django, there are several applications like django-registration-redux to perform these tasks, but the major drawback is that...

6 minutes read.