User:Akash1806/Django (web framework)

Django is a free and open source web application framework, written in Python, which follows the model–view–controller (MVC) architectural pattern. It is maintained by the Django Software Foundation (DSF), an independent organization established as a 501(c)(3) non-profit.

Django's primary goal is to ease the creation of complex, database-driven websites. Django emphasizes reusability and "pluggability" of components, rapid development, and the principle of don't repeat yourself. Python is used throughout, even for settings, files, and data models. Django also provides an optional administrative create, read, update and delete interface that is generated dynamically through introspection and configured via admin models.

Some well-known sites that use Django include Pinterest, Instagram, Mozilla, The Washington Times, Disqus, the Public Broadcasting Service, Bitbucket and NASA Science.

History
Django was born in the fall of 2003, when the web programmers at the Lawrence Journal-World newspaper, Adrian Holovaty and Simon Willison, began using Python to build applications. It was released publicly under a BSD license in July 2005. The framework was named after guitarist Django Reinhardt.

Django originated to solve the problem of building content delivering websites fast enough to keep up with the pace of a news organization. It is considered to be well suited for developing Content management systems and database driven websites. This suitability can be attributed to its useful features like - a default admin site that comes bundled with every Django application and is considered a typical part of such systems, an MVC based architecture which calls for separation of code that deals with data and business logic, etc. Some of the particularly popular example of CRM systems built using Django are Mezzazine, djangoCMS and Koalix.

In June 2008, it was announced that a newly formed Django Software Foundation (DSF) would maintain Django in the future.

The latest stable version of Django, 1.8.5, was released on October 3, 2015.

Components
Despite having its own nomenclature, such as naming the callable objects generating the HTTP responses "views", the core Django framework can be seen as MVC. It consists of an object-relational mapper (ORM) which mediates between data models (defined as Python classes) and a relational database ("Model"); a system for processing HTTP requests with a web templating system ("View") and a regular-expression-based URL dispatcher ("Controller").

Also included in the core framework are:
 * a lightweight and standalone web server for development and testing
 * a form serialization and validation system which can translate between HTML forms and values suitable for storage in the database
 * a template system that utilizes the concept of inheritance borrowed from object-oriented programming
 * a caching framework which can use any of several cache methods
 * support for middleware classes which can intervene at various stages of request processing and carry out custom functions
 * an internal dispatcher system which allows components of an application to communicate events to each other via pre-defined signals
 * an internationalization system, including translations of Django's own components into a variety of languages
 * a serialization system which can produce and read XML and/or JSON representations of Django model instances
 * a system for extending the capabilities of the template engine
 * an interface to Python's built in unit test framework

Templates
Templates provide a way to generate HTML dynamically and present the data generated in response to a request. Any application can optionally choose one or more of several templating engines provided by Django and third parties. Django's built in template system is called Django Template System(DTS). A popular third party choice for a templating engine is Jinja2. Django provides the option of having more than one template engine for a project from version 1.8 onward. A sample template will look like the following:

The Admin site
One of the most powerful features of Django is the production ready admin site that is automatically generated for every Django project. It interacts with models to provide an interface for feeding data in to the website. The default admin site provides a lot of useful features out of the box like :
 * an access control list, which allows to create and remove users and their respective privileges,
 * configuring which models need to be exposed to admin interface,
 * simple and useful design providing basic Create, Read, Update and Delete(CRUD) operations
 * easily customizable views to the specific application needs

Bundled applications
The main Django distribution also bundles a number of applications in its "contrib". package, including:
 * an extensible authentication system
 * the dynamic administrative interface
 * tools for generating RSS and Atom syndication feeds
 * a sites framework that allows one Django installation to run multiple websites, each with their own content and applications
 * tools for generating Google Sitemaps
 * built-in mitigation for cross-site request forgery, cross-site scripting, SQL injection, password cracking and other typical web attacks, most of them turned on by default
 * a framework for creating GIS applications

Extensibility
Django's configuration system allows third party code to be plugged into a regular project, provided that it follows the reusable app conventions. More than 2500 packages are available to extend the framework's original behavior, providing solutions to issues the original tool didn't: registration, search, API provision and consumption, CMS, etc.

This extensibility is, however, mitigated by internal components dependencies. While the Django philosophy implies loose coupling, the template filters and tags assume one engine implementation, and both the auth and admin bundled applications require the use of the internal ORM. None of these filters or bundled apps are mandatory to run a Django project, but reusable apps tend to depend on them, encouraging developers to keep using the official stack in order to benefit fully from the apps ecosystem.

Server arrangements
Django can be run in conjunction with Apache, NGINX using WSGI, Gunicorn, or Cherokee using flup (a Python module). Django also includes the ability to launch a FastCGI server, enabling use behind any web server which supports FastCGI, such as Lighttpd or Hiawatha. It is also possible to use other WSGI-compliant web servers. Django officially supports four database backends: PostgreSQL, MySQL, SQLite, and Oracle. Microsoft SQL Server can be used with django-mssql on Microsoft operating systems, while similarly external backends exist for IBM DB2, SQL Anywhere and Firebird. There is a fork named django-nonrel, which supports NoSQL databases, such as MongoDB and Google App Engine's Datastore.

Django may also be run in conjunction with Jython on any Java EE application server such as GlassFish or JBoss. In this case django-jython must be installed in order to provide JDBC drivers for database connectivity, which also provides functionality to compile Django in to a .war suitable for deployment.

Google App Engine includes support for Django version 1.x.x as one of the bundled frameworks.Heroku also includes support for Django version 1.x.x.

Comparison with other MVC frameworks
Django is among the most popular web development frameworks, and is topped by Microsoft’s ASP.net and Ruby on Rails in popularity. .

Source availability
Django and Ruby on rails are both free and open sourced , while ASP.net has recently been open sourced in 2014, with Microsoft Visual Studio, the Integrated development environment for ASP.net, still being closed source and maintained by Microsoft.

DRY Principle
All the three frameworks favor the "Don't Repeat Yourself", or the DRY principle for writing applications and thereby emphasize on writing less redundant and more reusable code .

Explicit over implicit
Django applications are written along the "Explicit over implicit", one of the aphorisms mentioned in [[Python Enhancement Proposal]] 20, The Zen of Python, and hence, widely followed in python programming. Rails application follow a contrary model, where the principle of Convention over configuration plays an important role in making many functionalities automatic without the need to explicitly write code for them. ASP.net also supports Convention over Configuration for faster development.

Database migration
Database migration provides a convenient way to create, modify and even change the relational database used by the application along with optionally providing version control like mechanism for the database schema. With version 1.8, Django has started supporting migrations natively, obviating the need for a third party migrations library like South. Rails has native support for database migration since its inception. . ASP.net supports migrations through the Entity framework migrations library.

ActiveRecord support
Active record is a an architectural pattern that simplifies reading and writing to databases from an application by mapping the database objects to corresponding objects in the application .Django and Rails both come with built-in support for Active record. ASP.net can only use Active records through third party libraries like Castle.

Default user authentication
User authentication is almost an omnipresent feature in most web applications which makes it an important candidate to be a part of default set of modules for any web framework. Django comes with bundled user authentication module for every project. Rails does not have a bundled authentication gem and one has to include a gem like Devise for this purpose. ASP.net also has a built in authentication module, called ASP.net Login Controls, that can be clubbed with any application.

Version managememnt
A version manager facilitate the use of different version of the framework for different projects. It can also maintain a completely disjoint set of helper modules for each project. Django manages its different versions across various projects through Python's Virtualenv isolated environment management tool. Rails uses rvm for the same purpose. ASP.net as yet, does not have a version manager like Django and Rails. DNVM, a package manager for ASP, is supposed to be part of ASP.net version 5.

Performance and optimization
Django serves some of the busiest websites on the internet handling billions of page views per month. Performance of Django websites can be improved by using appropriate production configurations for databases, page rendering etc. Some common optimizations used by Django websites to scale efficiently include:
 * setting the database connection to be persistent, instead of creating one on every request
 * using cached loading for templates instead of the default per request searching and loading model
 * use some for of in-memory caching for storing sessions. The default way is to store it in database,which may create a bottleneck.
 * optimize sql queries used by the application and identify and remove redundant ones

DjangoCon
There is a semiannual conference for Django developers and users, named "DjangoCon", that has been held since September 2008. DjangoCon is held annually in Europe, in May or June; while another is held in the United States in September, usually in Portland, Oregon. The 2012 DjangoCon took place in Washington D.C from 3 to 8 September. 2013 DjangoCon was held in Chicago at the Hyatt Regency Hotel and the post-conference Sprints were hosted at Digital Bootcamp, computer training center.

Django mini-conferences were held in Hobart, Australia in July 2013 and Brisbane, Australia in August 2014.

Other languages
Django's template design has been ported to other languages besides Python, providing decent cross-platform support. Some of these options are more direct ports, while others are inspired by Django, retaining its concepts but taking greater liberties to deviate from Django's design.
 * Swig for JavaScript
 * Liquid for Ruby
 * Template::Swig for Perl
 * Twig for PHP
 * Jinja for Python

Integrated development environments for Python
While a number of Django developers use text editors such as Vim, Emacs, TextMate or Sublime with Django Bundle for their projects, others prefer python-specific tools providing debugging, refactoring, unit testing, etc.
 * Anjuta
 * Aptana Studio with integrated PyDev
 * Codenvy
 * Eclipse with PyDev
 * Eric Python IDE
 * IntelliJ IDEA with Django plugin, provides functionality similar to PyCharm
 * Koding
 * Komodo IDE
 * Microsoft Visual Studio with Python Tools for Visual Studio
 * MonoDevelop
 * NetBeans with Django Plugin
 * Ninja IDE
 * PyCharm
 * PyScripter
 * Spyder (software)
 * SourceLair
 * Wing IDE

Criticism
Django is considered optimal choice for data driven websites and consequently not as well suited for not very dynamic websites. Other python frameworks like Pyramid have improved upon this aspect. It is built using the Active Record architecture pattern as opposed to the Unit of work pattern used in SQLAlchemy which is considered superior and adopted by Django's counterparts like Pyramid. It is not very well suited for smaller projects that do not use a database, as there is no way to turn off database integration in Django.