Python and Django
Python and Django
Framework
Mohit Gusain
140970101021
4th Year
Ducat Noida
Introduction of python
Python is a general-purpose interpreted, interactive, object-oriented, and
high-level programming language. It was created by Guido van Rossum
during 1985- 1990. Like Perl, Python source code is also available under the
GNU General Public License (GPL).
History of Python
Python was developed by Guido van Rossum in the late eighties and early
nineties at the National Research Institute for Mathematics and Computer
Science in the Netherlands.
Python is copyrighted. Like Perl, Python source code is now available under
the GNU General Public License (GPL).
Python Features
Python's features include:
Easy-to-read: Python code is more clearly defined and visible to the eyes.
A broad standard library: Python's bulk of the library is very portable and
Portable: Python can run on a wide variety of hardware platforms and has
the same interface on all platforms.
It provides very high-level dynamic data types and supports dynamic type
Checking.
It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java.
Python Environment
Python is available on a wide variety of platforms including Linux and Mac
OS X. Let's understand how to set up our Python environment.
Win 9x/NT/2000
OS/2
PalmOS
Windows CE
Acorn/RISC OS
BeOS
Amiga
VMS/OpenVMS
QNX
VxWorks
Psion
Python has also been ported to the Java and .NET virtual machines
Getting Python
The most up-to-date and current source code, binaries, documentation,
news, etc.,is available on the official website of Python:
http://www.python.org/.
Django
Django is a high-level Python web framework that encourages rapid
development and clean, pragmatic design. Django makes it easier to build
better web apps quickly and with less code.
History of Django
2003: Started by Adrian Holovaty and Simon Willison as an internal
project at the
2005: Released July 2005 and named it Django, after the jazz guitarist
Django
Reinhardt.
Clean Design: Django strictly maintains a clean design throughout its own
code and makes it easy to follow best web-development practices
Advantages of Django
Here are few advantages of using Django which can be listed out here:
Framework Support: Django has built-in support for Ajax, RSS, Caching
and various other frameworks.
Django-Overview
As you already know, Django is a Python web framework. And like most
modern framework, Django supports the MVC pattern. First let's see what is
the Model-View Controller (MVC) pattern, and then we will look at Djangos
specificity for the Model-View Template (MVT) pattern.
MVC Pattern
When talking about applications that provides UI (web or desktop), we
usually talk about MVC architecture. And as the name suggests, MVC pattern
is based on three components: Model, View, and Controller.
DJANGO MVC - MVT Pattern
The Model-View-Template (MVT) is slightly different from MVC. In fact the
main difference between the two patterns is that Django itself takes care of
the Controller part (Software Code that controls the interactions between the
Model and View), leaving us with the template. The template is a HTML file
mixed with Django Template Language (DTL).
The following diagram illustrates how each of the components of the MVT
pattern interacts with each other to serve a user request:
The developer provides the Model, the view and the template then just maps
it to a URL and Django does the magic to serve it to the user.
Django enviroment
Django development environment consists of installing and setting up
Python, Django, and a Database System. Since Django deals with web
application, it's worth mentioning that you would need a web server setup as
well.
$ python
Otherwise, you can download and install the latest version of Python from
the link http://www.python.org/download.
You can download the latest version of Django from the link
http://www.djangoproject.com/download.
You can use the package manager of your OS, or use easy_install or pip if
installed.
We will cover the second option as the first one depends on your OS
distribution. If you have decided to follow the first option, just be careful
about the version of Django you are installing.
Let's say you got your archive from the link above, it should be something
like Djangox.xx.tar.gz:
$ cd Django-x.xx
$ django-admin.py --version
If you see the current version of Django printed on the screen, then
everything is set.
Windows Installation
We assume you have your Django archive and python installed on your
computer.
On some version of windows (windows 7) you might need to make sure the
Path system variable has the path the following
C:\Python27\;C:\Python27\Lib\sitepackages\django\bin\
c:\>cd c:\Django-x.xx
Next, install Django by running the following command for which you will
need administrative privileges in windows shell "cmd":
To test your installation, open a command prompt and type the following
command.
c:\>django-admin.py --version
If you see the current version of Django printed on screen, then everything
is set.
OR
c:\> python
on your comfort.
1. MySQL (http://www.mysql.com/)
2. PostgreSQL (http://www.postgresql.org/)
3. SQLite 3 (http://www.sqlite.org/)
4. Oracle (http://www.oracle.com/)
5. MongoDb (https://django-mongodb-engine.readthedocs.org)
6. GoogleAppEngine Datastore
(https://cloud.google.com/appengine/articles/djangononrel)
Web Server
Django comes with a lightweight web server for developing and testing
applications. This server is pre-configured to work with Django, and more
importantly, it restarts whenever you modify the code.
However, Django does support Apache and other popular web servers such
as Lighttpd.