Python's Django Framework installation full guide

Source: Internet
Author: User
Tags gz file subversion client svn update install django version control system pprint
Python Installation

Django itself is written in pure Python, so the first step in installing the framework is to make sure you have Python installed.
Python version

The core Django Framework can work on any Python version between 2.3 and 2.6 (including 2.3 and 2.6). Django's optional GIS (Geographic information System) support requires Python 2.4 to 2.6.

If you're not sure what version of Python to install, and you're completely unsure, then choose the latest version of the 2.x series. Version 2.6. While Django works well under any Python version between version 2.3 and 2.6, the new version of Python offers some of the more rich and extra language features you might want to apply to your program. In addition, some of the Django third-party plugins you might want to use will require newer versions than Python 2.3, so using a newer version of Python will give you more options.

Django and Python 3.0

PYTHON3.0 has been published while writing this book, but Django does not support it for the time being. Python3.0 The language itself introduces a lot of non-backward compatibility changes, so we expect most of the major Python libraries and frameworks will take years to converge, including Django.

If you are a novice python and are confused about whether you are learning Python 2.x or Python 3.x, we recommend that you choose Python 2.x.

If you are using Linux or Mac OS X, the system may already have Python preinstalled. Enter Python at the command prompt (or terminal in OS x), and if you see the following information, Python is already installed: Enter python in the Command Line window (or in the Program/tool/terminal of OS X). If you see this information, Python is already installed.

Python 2.4.1 (#2, Mar 2005, 00:05:10) [GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on Darwintype "help", "Copyri Ght "," credits "or" license "for more information.>>>

Otherwise, you will need to download and install Python. It is fast and convenient, and the detailed description can refer to
Installing Django

At any time, there are two different versions of Django for you to choose from. The latest official release and a risky backbone version. The version that is installed depends on your preference. You need a stable, tested Django, or a version that you want to include with the latest features, maybe you can contribute to Django itself and stabilize as a price?

We recommend selecting a full release version, but it is important to understand the existence of the skeleton development version, as you will find it mentioned in the documentation and community members.
Install the official release version

The official release version comes with a version number, such as 1.0.3 or 1.1, and the latest version is always available in

If you're using a Linux system that includes a Django package, it's a good idea to use the default version. This way, you will get a secure upgrade through the system's package management.

If your system does not own Django, you can download and install the framework yourself. First, the download name is similar to the django-1.0.2-final.tar.gz compressed file. (It doesn't matter where you download it, and the installer puts the Django file in the right place.) After decompression, run install, like most Python libraries.

Here's how to install on a UNIX system:

  Tar xzvf django-*.tar.gz   CD django-*   

On Windows systems, it is recommended to use 7-zip ( to extract the. tar.gz file. After the decompression is complete, start a DOS Shell (Command prompt) with administrator privileges, and then execute the following command in the directory where the name begins with django-:

Python Install

If you're curious: Django will be installed in your Python installation directory "site-package" directory (Python looks for third party libraries from this directory). Typically, this directory is in/usr/lib/python2.4/site-packages.
Installing the trunk version

The latest and best Django development version is called a trunk and can be obtained from Django's subversion. If you want to have an early taste, or want to contribute code to Django, you should install this version.

Subversion is a free, open source version control system similar to CVS that the Django development team uses to manage updates to the Django code base. You can use the Subversion client to get the latest Django source code, and you can update the local Django code version at any time with the native checkout to get the latest updates and improvements made by the Django developer.

Keep in mind that even using the trunk version is guaranteed. Because many Django developers are using the trunk version on the official website, they will guarantee the stability of the trunk version.

Follow these steps to get the latest Django mainstream code:

    • Make sure the Subversion client is installed. You can download the software from free and get excellent documentation from
    • (If you're using Mac OS X 10.5 or later, you're lucky that subversion should be able to install Django.) You can verify this by entering SVN--version on the terminal.
    • Use the SVN Co djtrunk command to view the body code.
    • Find your Python's site-packages directory. Generally/usr/lib/python2.4/site-packages, if you are unsure, you can enter the following command:
    • Python-c ' Import sys, pprint; Pprint.pprint (Sys.path) '
    • The above results will contain the Site-packages directory
    • In the Site-packages directory, create a file django.pth, edit the file that contains the full path profit for the Djtrunk directory, which contains the following line:

    • Add Djtrunk/django/bin to the system variable PATH. This directory contains administrative tools such as This directory contains administrative tools, for example:


If you have not contacted the. pth file, you can learn more about it from

After downloading and performing the previous steps from Subversion, there is no need to execute the Python install again, you have just completed the installation manually!

Since the updates to the Django skeleton code often include bug fixes and feature additions, you might want to update them every few minutes if you're really fascinated. Run the SVN update command in the Djtrunk directory to update it. When you use this command, Subversion will contact to determine if the code is updated and then apply any changes since the last update to the local code. It's so simple.

Finally, if you use trunk, you need to know which trunk version you are using. If you go to the community for help, or provide improvements to the Django framework, it's important to know the version number you're using. So when you go to the community to ask for help, or if you want to provide improvements to Django, always remember the version number of the Django you're using. How do I know the version number of the Django you are using? Go to the ' djtrunk ' directory and type SVN info to see Revision in the Output information: (version:) followed by the number. Each time Django is updated, the version number is incremented, whether it's fixing bugs, adding features, improving documentation, or something else. In some Django communities, the version number has even become a symbol of honor, and I've already used Djano since [writing a very low version number].
Test your Django Installation

Let's take some time to test if Django is installed successfully and works well. You can also learn some clear post-installation feedback. In the shell, change to another directory (not the one that contains the Django directory), and then enter Python to open the Python interaction interpreter. If the installation is successful, you should be able to import the Django module:

>>> Import django>>> Django. VERSION (1, 1, 0, final ', 1)

Interactive Interpreter Example

The Python interactive interpreter is a command-line window program that allows you to write Python programs interactively. To start it just run the python command.

We demonstrate the Python example in the interactive interpreter that will run through the entire book. You can use the three greater than sign (>>>) to distinguish the sample, three greater than the number represents the interactive prompt. If you want to copy the example from this book, do not copy the prompt.

In the interactive interpreter, a multiline declaration uses three points (...). ) to fill. For example:

>>> print "" "This is a ... string that spans ... three lines." " This is astring that Spansthree lines.>>> def my_function (value): ...   Print value>>> my_function (' hello ') hello

These three points are inserted at the beginning of the new line and are added by the Python shell itself, not our input. But they are included to pursue the correct output of the interpreter. If you copy our example to run, never copy these points.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.