What is Django?
Django Web Framework is a free and open-source web framework which is written in Python and abides by the MVT (Model View Template) pattern. It is maintained and authorized by the Django Software Foundation (DSF) which is an independent organization established firmly as a non-profit foundation.
Django’s primary most goal is to simplify the creation of complex websites which are also data-driven ones. Django emphasizes much on reusability of components, lessening codes, lowering coupling, rapidity in development, etc. Python is used incessantly in most of the tasks, including file settings and data models. Django also provides a voluntary administration to create, read, update and delete the interface that is generated through introspection and further configured by admin models.
Some well-known sites that involve the usage of Django include the Public Broadcasting Service, Instagram, Mozilla, The Washington Times, Disqus, Bitbucket, etc. It also had its usage in Pinterest, but later the site was reported to have moved on to some other framework.
How was Django created?
Django was invented and created in the Autumn of 2003, by two web programmers working at the Lawrence Journal-World newspaper, Adrian Holovaty and Simon Willison, who began using Python to develop and build applications. It was released in public along with a BSD license in July in the year 2005. The framework was initially named after the guitarist Django Reinhardt.
In June 2008, it was further announced that a newly formed Django Software Foundation (DSF) would carry out the maintenance of Django in the future.
How to use a Django Framework?
Let’s see in the following steps ‘how to properly configure our computer to work on Django projects’?
We start with an overview of the command line and then use it for installing the latest versions of both Django (2.1) and Python (3.7). Then we will discuss the next steps like virtual environments, Git installation and working with a text editor.
The Command Line
The command line is a prevailing, text-only view of the computer. On a Mac system, the command line is found in a program called Terminal which is located at Applications/Utilities. To initiate it, a new Finder window is to be opened, open the Applications folder, scroll down further to open the utility folder, and then double-click the application called Terminal.
On Windows system, there is a built-in command line program which is difficult to use. It is recommended to use Babun instead, which is a free and open-source command line program. On the Babun homepage, click on the “Download now” button, double-click the downloaded file to install Babun, and on completion drag the installer to the Recycle Bin. To use it, go to the Start menu, select Programs, and then click on Babun.
Going forward when the Babun is referring to the “command line”, it aims to open a new console on the computer using Terminal or Babun.
Though there are many possible commands one can use, six most frequently used commands in Django development are:
- cd (change down a directory)
- cd .. (change up a directory)
- ls (list files in your current directory)
- pwd (print working directory)
- mkdir (make directory)
- touch (create a new record)
The command line is further opened and tried. The ‘$’ sign is the primary command line prompt i.e. all other commands are written after the ‘$’ prompt.
Install Python 3 on Windows:
Windows does not install Python by default, however, it can be checked if any version exists on the system. The steps include opening a command line console by entering the specific command on the Start Menu. Or one can hold down the SHIFT key while right-clicking on the desktop, and then select Open Command Window thereafter.
The following command is to be written and then hit RETURN thereafter –
If you see output like this –
version Python 3.7.0
It implies Python is already installed. Most likely there will be no version available.
After Python has been established, run the following command in a new command line console:
python –version Python 3.7.0
If this works, you will have less work to do.
Virtual environments are an essential and an indispensable part of Python programming. They are like a separate container which contains all the software dependencies required for a given project. This is very important as by default software like Python and Django are installed in the same directory. This, in turn, can cause problems when one wants to work on multiple projects on the same computer.
Going by history, Python developers have either used virtualenv or pyenv to configure virtual environments. But recently in 2017 prominent Python developer Kenneth Reitz created and released Pipenv, which is now the officially recommended Python packaging tool.
Pippen is quite similar to npm and yarn from the Node ecosystem. In Pippen, a Zip file is created containing software dependencies, and a Pipfile.lock is established to ensure deterministic builds.
The result is a new virtual environment with Pipenv is created for each new Django Project.
To view Pipenv in action, a new directory is created and then Django is installed. To accomplish this, first navigate to Desktop, then create a new list ‘Django’ and enter it with cd
$ cd ~/Desktop $ mkdir Django $ cd Django
Now use Pipenv to install Django.
$ piping install django==2.1
If one looks within the directory, then there are two new files: Pipfile and Pipfile.lock. No one has the information one needs for a new virtual environment as it has not been activated yet. The activation is done through the use of the piping shell.
$ piping shell
It is to be noted that due to an open bug, Windows users often do not see the visual feedback of the virtual environment. But if one can run Django-admin start project in the next section, then it’s known for sure that the virtual environment has Django installed.
Git is an indispensable part of modern software development. It is a version control system which can be used as a potent version of track changes in Microsoft Word, Google Docs, etc. With it, one can collaborate easily with other developers, track all work via commits, and then revert to any previous version of the code even if one accidentally deletes something valuable.
The final step involved in the text editor. While the command line is the place where one executes commands for the programs, a text editor is where the main code is written. The computer doesn’t see what text editor is used. The code is the result. A good text editor can provide with helpful hints and catch typos.
Excellent and experienced developers prefer using either Vim or Emacs, text-only editors with excellent and loyal followings. Though, each involves a steep learning curve and requires thorough memorizing of various keystroke combinations.
Modern text editors often combine the same powerful features with an excellent visual interface. One of the favorites is Visual Studio Code, which is free, easy to install, and enjoys quite a widespread popularity.
Applications Of Django Framework:
Django programming framework is chosen for building web and mobile applications for some of the following reasons –
1. The first reason is its ability to give the best solutions and results to the clients.
2. An online news operation first developed Django with the aim to quickly and efficiently create reliable web applications using the Python programming language. This framework has templates, libraries, and API designed, working together for the natural growth and connectivity. In practice, this means the apps built in Django have the potential to be grown with minimal costs in upgrades, changes, and additions.
3. Django suits to projects of any size, from the smallest to the biggest ones. Due to its good scalability, it is perfect for startups. Also, it also serves as a great help in facing hundreds of visitors per second, such as Disqus, Washington Post, etc.
4. Django uses Python which is one of the most popular programming languages and is the most popular language for those learning to code in present times. The framework itself is very widely used, and because it’s an open-source, it is built and kept regularly updated by the developers who use it. This implies one can easily find answers to questions arising from one’s project created in Django/Python.
Nobody likes configuring a local development environment. Fortunately, the entire process is but a one-time pain. Now that you have learnt how to work with virtual environments and to install the latest version of Python and Git, everything is just fine and you are ready to develop your first Django app.