Django installation


Before installing Django, the system needs to have a Python development environment installed. Next, let’s take a closer look at the installation of Django under different systems.


Installing Django under Window

If you have not installed the Python environment, you need to download the Python installation package first.

1. Python download address: https://www.python.org/downloads/

2. Django download address: https://www.djangoproject.com/download/

Note: Currently Django 1.6.x or above is fully compatible with Python 3.x.

Python installation (already installed can be skipped)

To install Python, you only need to download the python-x.x.x.msi file, and then keep clicking the "Next" button.

install1.png

After the installation is complete, you need to set the Python environment variables. Right-click Computer->Properties->Advanced->Environment Variables->Modify the system variable path and add the Python installation address. The example in this article uses C:\Python33. You need to install it according to your actual situation.

1025.png

Django installation


Download the Django compressed package, unzip it and put it in the same root directory as the Python installation directory, enter the Django directory, and execute python setup.py install, and then start the installation. Django will be installed into Python's Lib site-packages.


install3.jpg

#Then configure the environment variables and add these directories to the system environment variables: C:/Python33/Lib/site-packages/django;C:/Python33/Scripts. After the addition is completed, you can use Django's django-admin.py command to create a new project.

install4.jpg

Check whether the installation is successful

Enter the following command to check:

python                   

import django
django.get_version()
install5.jpg

If the Django version number is output, it means the installation is correct.


Installing Django on Linux

yum installation method

The following installation is installed in Centos Linux environment. If your Linux system is ubuntu, please use apt-get Order.

The Linux environment already supports Python by default. You can enter the Python command in the terminal to check whether it is installed.

Python 2.7.3 (default, Aug  1 2012, 05:14:39) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

Install setuptools

Command:

yum install setuptools

After completion, you can use the easy_install command to install django


easy_install django

After that, we enter the following code in the python interpreter:

[root@solar django]# python
Python 2.7.3 (default, May 15 2014, 14:49:08)
[GCC 4.8.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.VERSION
(1, 6, 5, 'final', 0)
>>>

We can see that the version number of Django is output, indicating that the installation is successful.

pip command installation method

pip install Django

Source code installation method

Download the source code package: https://www.djangoproject.com/download/

Enter the following Command and install:

tar xzvf Django-X.Y.tar.gz    # 解压下载包
cd Django-X.Y                 # 进入 Django 目录
python setup.py install       # 执行安装命令

After successful installation, Django is located in the site-packages directory of the Python installation directory.


Installation under Mac

Download

Download the latest stable version from here: DJango-1.x.y.tar.gz, download from the list on the right side of the page, as shown below:


1038.jpg


Remember it is the latest official version. Where x.y is the version number. Enter the folder directory where you downloaded the file and execute the following command: (The default on Mac is /Users/xxx/Downloads, xxx is your user name)


$ tar zxvf Django-1.x.y.tar.gz

You can also download it from Download the latest version on Github, address: https://github.com/django/django:

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

Installation

Enter the decompressed directory:

cd Django-1.x.y
sudo python setup.py install

After successful installation The following information will be output:

……
Processing dependencies for Django==1.x.y
Finished processing dependencies for Django==1.x.y

Then enter our site directory and create a Django project:

$ django-admin.py startproject testdj

Start the service:

cd testdj # 切换到我们创建的项目
$ python manage.py runserver
……
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

The above information indicates that the project has been started, access address is http://127.0.0.1:8000/.