Introduction to Django — a full-stack Python framework
Django is a famous full-stack python framework that follows the “battery included” philosophy. “Battery-included” means common functionalities required for building web application comes along with framework rather than as separate libraries. Some of the popular websites like Spotify, Instagram, YouTube, Pinterest, Quora are built using Django.
Why Django?
First of all, it's based on python, one of the most widely accepted and easiest language, well known for its community and vast libraries.
Django is well known for its performance, stability, and community. And their official documentation is one of the best in software development. Whatever complex task you need to do there would be some package available to do all the heavy lifting. Also, Django keeps track of each web vulnerability that arises each day and issues a fix as soon as it's discovered, thereby making your web application more secure.
A Little about History
According to the Django Software Foundation, Django was “invented to meet fast-moving newsroom deadlines, while satisfying the tough requirements of experienced web developers.” The framework was invented by Adrian Holovaty and Simon Willison, developers who worked at the news website World Online. At the time, Adrian and Simon were writing in PHP. But since the World Online website required quick updating, it became hard to meet deadlines. Adrian and Simon needed something they could build the website with quickly. That was when they decided to move to Python. Later on, they started working on Django to make coding even simpler and more effective. In 2005, Django was already publicly released as an open-source project. Today, Django is known as
The web framework for perfectionists with deadlines.
Setting Up
First, you would need python to be installed in your system, if not installed install it now.
I highly advise using virtual environments while doing any python project.
If you have never used a virtual environment before, run
python -m pip install --user virtualenv
or checkout here.
If you have a newer version of python (python 3.5+) it is recommended to install virtualenv using pipx. It isolates virtualenv and does not affect other parts of your operating system.
pipx install virtualenv
Now install Django into a virtual environment that you create.
To create a virtual environment
virtualenv .env
.env can be any name. Now a .env folder will be created inside the current directory.
source .env/bin/activate
Activates the current virtual environment.
python -m pip install Django
To stop using the current virtual environment at any point, run
deactivate
To create a new Django project run
django-admin startproject myproject
This will give a folder named myproject and some files in it.
To run the server, run the command
python manage.py runserver
This will open a server on http://127.0.0.1:8000/
More into Django project structure and its usage will be discussed in upcoming articles