Django

Mudit Arora
7 min readDec 3, 2018

Django is a project-based approach to learning web development. Django is a free, open source web framework written in the Python programming language and used by millions of programmers every year. Its popularity is due to its friendliness to both beginners and advanced programmers.

Why Django?

A web framework is a collection of modular tools that abstracts away much of the difficulty–and repetition–inherent in web development. Django inherited Python’s “batteries-included” approach and includes out-of-the box support for common tasks in web development:

  • user authentication
  • templates, routes, and views
  • admin interface
  • robust security
  • support for multiple database backends
  • and much much more

Applications Of Django

  1. Disqus

This is one of the largest Django projects so far. Mostly recognized as a popular and easy-to-use plug-in for comments, it also features an advanced analytics tool and configurable ad serving.

2. Instagram

This Python-based photo and video-sharing social network is crazy popular, and it needs to process huge amounts of data and manage an even greater number of interactions between users every single second.

3. Spotify

Spotify is an app used for listening to music, making its wide library accessible to everyone on any device. To develop the app, Spotify bet on Python for both backend services and machine learning. And in order to make the most of this programming language, they also combined it with the Django framework.

4. YouTube

There’s no need to introduce this website, since it’s already become a synonym for the term “video-sharing platform”. Originally it was a PHP-based project, but the constant need to improve its performance and add new functionalities forced YT to turn to Python as well. Django is a big help to the YouTube team of developers, allowing them to act quickly and flawlessly.

5. The Washington Post

Today, some of the biggest titles in the world also take advantage of Lawrence Journal-World newspaper publisher! Django allows The Washington Post website to handle huge traffic, providing fast and efficient performance.

6. Bitbucket

This cloud-based Git repository hosting service was launched in 2008. Ten years later, the platform is used by millions of developers, who in 2017 alone merged 17 million pull requests and created 6 million repositories. And the core technology behind it is Python paired with the Django framework. Bitbucket developers praise Django for its wide and vibrant community, as well as for the fact that it offers so many parts that are ready to use.

7. Dropbox

Dropbox is one of the most popular cloud storage services for documents, videos, pictures, and so on. This online drive is available for various devices, allowing its users to access it anywhere, anytime. The platform is powered primarily by Python, which is why it was able to develop so fast. Dropbox devs also chose the Django framework to enable storing, synchronization, and sharing options for various types of files.

8. Eventbrite

The website was launched in 2006 as an event management and ticketing service. It was originally written in Python, on top of a few in-house frameworks that simply became inefficient as the platform experienced rapid growth. In 2010, the Eventbrite dev team took its firsts steps towards moving to the Django web framework.

9. Mozilla

Not all of its components are written in Python, but all the new ones are, and they also take advantage of Django

10. Prezi

Prezi is a beautifully designed web-based presentation software — a pretty powerful alternative to Microsoft PowerPoint. It features a map-like overview with zoom-in/zoom-out options instead of the classic slide-based format. But the most interesting part of this project is that they stuck with Django from the very beginning because they wanted to be able to scale seamlessly, and in the most effective way — both in terms of time and costs.

How to install Django

Django is a Python Web framework. Get the latest version of Python at https://www.python.org/downloads/

Install Apache and mod_wsgi

If you want to use Django on a production site, use Apache with mod_wsgi. mod_wsgi operates in one of two modes: embedded mode or daemon mode. In embedded mode, mod_wsgi is similar to mod_perl — it embeds Python within Apache and loads Python code into memory when the server starts. In daemon mode, mod_wsgi spawns an independent daemon process that handles requests. The daemon process can run as a different user than the Web server, possibly leading to improved security. The daemon process can be restarted without restarting the entire Apache Web server, possibly making refreshing your codebase more seamless. Make sure you have Apache installed with the mod_wsgi module activated. Django will work with any version of Apache that supports mod_wsgi.

Get your database running

If you plan to use Django’s database API functionality, you’ll need to make sure a database server is running. Django supports many different database servers and is officially supported with PostgreSQL, MySQL, Oracle and SQLite. In addition to a database backend, you’ll need to make sure your Python database bindings are installed.

If you plan to use Django’s manage.py migrate command to automatically create database tables for your models (after first installing Django and creating a project), you’ll need to ensure that Django has permission to create and alter tables in the database you’re using; if you plan to manually create the tables, you can simply grant Django SELECT, INSERT, UPDATE and DELETE permissions. After creating a database user with these permissions, you’ll specify the details in your project’s settings file, see DATABASES for details. If you’re using Django’s testing framework to test database queries, Django will need permission to create a test database.

Install the Django code

Installation instructions are slightly different depending on whether you’re installing a distribution-specific package, downloading the latest official release, or fetching the latest development version.

Installing an official release with pip

This is the recommended way to install Django.

  1. Install pip. The easiest is to use the standalone pip installer. If your distribution already has pip installed, you might need to update it if it’s outdated. If it’s outdated, you’ll know because installation won’t work.
  2. Take a look at virtualenv and virtualenvwrapper. These tools provide isolated Python environments, which are more practical than installing packages systemwide. They also allow installing packages without administrator privileges. The contributing tutorial walks through how to create a virtualenv.
  3. After you’ve created and activated a virtual environment, enter the command pip install Django at the shell prompt.

Installing a distribution-specific package

Check the distribution specific notes to see if your platform/distribution provides official Django packages/installers.

Installing the development version

  1. Make sure that you have Git installed and that you can run its commands from a shell. (Enter git help at a shell prompt to test this.)

2. Check out Django’s main development branch like so:

git clone https://github.com/django/django.git

3. Make sure that the Python interpreter can load Django’s code. The most convenient way to do this is to use virtualenv, virtualenvwrapper, and pip. The contributing tutorial walks through how to create a virtualen.

4. After setting up and activating the virtualenv, run the following command:

pip install -e django/

Now, you are all set.

Usage of basic operations

  1. CRUD

Create — that one is rather straightforward. Standard support for it comes from the HTTP POST method. Because we’re creating a set element here (in particular, the object’s ID will be only determined now), we treat this method as an operation on the list: creating an element.

Retrieve — we have two options here: we can download a list of objects of a given type (list) or one specific object (retrieve). In both cases, GET will be the adequate HTTP method.

Update — There are two HTTP methods available here: PUT and PATCH. The difference between them is that according to its definition, PUT requires all attributes of the object — including those that have not changed. PATCH, on the other hand, allows entering only those fields that have actually changed, which is why it’s more popular. Using the PUT or PATCH method to update multiple objects is rare and DRF only supports updating single object in its default CRUD.

Delete — this deletes one or many objects. The HTTP method here will be DELETE. In practice, for security reasons, it’s usually not possible to remove several objects at the same time and again, DRF only supports this operation on single objects in its default CRUD.

2. PUT

The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-URI refers to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the one residing on the origin server. If the Request-URIdoes not point to an existing resource, and that URI is capable of being defined as a new resource by the requesting user agent, the origin server can create the resource with that URI. That is, PUT is used to create or update.

3. POST

The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line In other words, POST is used to create.

4. GET

The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI. If the Request-URI refers to a data-producing process, it is the produced data which shall be returned as the entity in the response and not the source text of the process, unless that text happens to be the output of the process.

Conclusion

Django is an excellent choice for any developer who wants to build modern, robust web applications with a minimal amount of code. It is popular, under active development, and thoroughly battle-tested by the largest websites in the world.

This task was completed as a part of Google Code-in 2018.

Google Code-in is a contest to introduce pre-university students (ages 13–17) to open source software development. Since 2010, over 3200 students from 99 countries have completed work in the contest.

View Contest: https://codein.withgoogle.com/

JBoss Community @ Google Code-In : https://codein.withgoogle.com/organizations/jboss-community/

--

--