English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
If you are on the latest Linux or Mac OS X, Python may already be installed on these systems. You can verify it by typing the command: python at the command prompt. If you see an output similar to the following, then it means Python is already installed.
# Filename : example.py # Copyright : 2020 By w3codebox # Author by: www.oldtoolbag.com # Date : 2020-08-08 $ python Python 2.7.5 (default, Jun 17 2014, 18:11:42) [GCC 4.8.2 20140120 (Red Hat 4.8.2-16) on Linux2
Otherwise, you can download and install the latest version of Python from the following link: http://www.python.org/download. Below are the corresponding versions:
Django version | Python version |
1.8 | 2.7, 3.2 (until the end of 2016, 3.3, 3.4, 3.5 |
1.9, 1.10 | 2.7, 3.4, 3.5 |
Installing Django is easy, but the steps required for installation depend on your operating system. Because Python is a platform-independent language, Django has a package that can work anywhere, regardless of your operating system.
You can download the latest version of Django from the following link: http://www.djangoproject.com/download.
Note: This tutorial is based on Windows7 64bit as an example for development.
If you are running Linux or Mac OS, there are two ways to install Django −
You can install using package managers available on your operating system with easy_install or pip. Before manually installing, you need to manually download the official compressed package.We will introduce the second option as the first, depending on the type of your operating system. If you decide to go with the first option, it is important to note the version of Django you are installing.
For example, if you downloaded the compressed package from the above link, it should be similar to this Django x.xx.tar.gz:
Extract and install.
# Filename : example.py # Copyright : 2020 By w3codebox # Author by: www.oldtoolbag.com # Date : 2020-08-08 $ tar xzvf Django-x.xx.tar.gz $ cd Django-x.xx $ sudo python setup.py install
You can test your installation by running the following command −
# Filename : example.py # Copyright : 2020 By w3codebox # Author by: www.oldtoolbag.com # Date : 2020-08-08 $ django-admin.py --version
If you see the current Django version printed on the screen, then everything is set up correctly.
Note - For some versions of Django, it will be django-delete the '.py' of admin
Windows installation
In this tutorial, we use the Windows system to explain the demonstration example, assuming that Django and Python are installed on the computer.
First, path verification.
In some versions of Windows (Windows7) may need to ensure that the Path system variable path is as follows, C:\Python27\;C:\Python27\Lib\site-packages\django\bin\, of course, this depends on your Python version.
Then, extract and install Django, here we put it in the directory C:\Python27\Django-1.9.1
# Filename : example.py # Copyright : 2020 By w3codebox # Author by: www.oldtoolbag.com # Date : 2020-08-08 c:\Python27\Django-1.9.1>
Next, to install Django, you need to run the following command, and you need administrator privileges to execute the Shell command 'cmd' -
# Filename : example.py # Copyright : 2020 By w3codebox # Author by: www.oldtoolbag.com # Date : 2020-08-08 C:\Python27\Django-1.9.1>python setup.py install
After a while, the result displayed will be as shown in the following figure:
To test your installation, open the command prompt and then type the following command−
# Filename : example.py # Copyright : 2020 By w3codebox # Author by: www.oldtoolbag.com # Date : 2020-08-08 c:\>django-admin.py --version
If you see the current version of Django displayed on the screen, then everything is set up OK.
or
Enter the 'cmd' prompt, then type python, then -
# Filename : example.py # Copyright : 2020 By w3codebox # Author by: www.oldtoolbag.com # Date : 2020-08-08 c:\> python >>> import django >>> print django.get_version()
Django supports several major database engines that you can choose according to your requirements.
MySQL (http://www.mysql.com/) PostgreSQL (http://www.postgresql.org/) SQLite 3 (http://www.sqlite.org/) Oracle (http://www.oracle.com/) MongoDb (https://django-mongodb-engine.readthedocs.org) GoogleAppEngine Datastore (https://cloud.google.com/appengine/articles/django-nonrel)You can refer to the corresponding documentation to install and configure the database of your choice.
Note - Chapter5and6is a NoSQL database.
Django comes with a lightweight web server for development and testing applications. This server is pre-configured to support Django-related work, and more importantly, it will restart after the developer saves changes to the code.
However, Django supports Apache and other popular web servers such as lighttpd. We will discuss these two different instances in subsequent chapters.