Python Django framework Installation Guide, pythondjango

Source: Internet
Author: User
Tags gz file subversion client install django pprint

Python Django framework Installation Guide, pythondjango

Python Installation

Django is written in Python only, so the first step to installing the framework is to ensure that you have installed Python.
Python version

The core Django framework can work in any Python version between 2.3 and 2.6 (including 2.3 and 2.6. Django's optional GIS (Geographic Information System) supports Python 2.4 to 2.6.

If you are not sure about the version of Python to be installed, and you have no idea about it, select the latest version of the 2. x series. Version 2.6. Although Django runs well in any Python version between Version 2.3 and version 2.6, the new version of Python provides some that you may want to apply in your program, more abundant and additional language features. In addition, some third-party Django plug-ins you may want to use require a version later than Python 2.3. Therefore, using a newer Python version gives you more options.

Django & Python 3.0

At the time of writing this book, Python3.0 has been released, but Django does not yet support it. Python3.0 introduces a lot of backward compatible changes. Therefore, we expect that most major Python libraries and frameworks will take several years to connect, including Django.

If you are a beginner in Python and are confused about whether to learn Python 2.x or Python 3.x, we recommend that you choose Python 2.x.
Install

If you are using Linux or Mac OS X, the system may have pre-installed Python. Input python in the command prompt (or OS X terminal). If the following information is displayed, it indicates that Python has been installed: input python in the command line window (or in the OS X program/tool/terminal ). If you see this information, it indicates that python has been installed.

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

Otherwise, you need to download and install Python. It is fast and convenient, and detailed instructions can refer to http://www.python.org/download/
Install Django

At any time, there are two different versions of Django for you to choose from. The latest official release and risky master versions. The installed version depends on your priority. You need a stable tested Django or a version that includes the latest features. Maybe you can contribute to Django and take stability as a price?

We recommend that you select a formal release version, but it is important to understand the existence of the main development version, because you will find it mentioned in documents and community members.
Install the official release

The official version comes with a version number, such as 1.0.3 or 1.1. The latest version can always be found at http://www.djangoproject.com/download.

If you are using a Linux system, including the Django package, it is a good idea to use the default version. In this way, you will be securely upgraded through system package management.

If your system does not contain Django, you can download and install the framework on your own. First, download the compressed file named django-1.0.2-final.tar.gz. (It doesn't matter where the file is downloaded. The installer puts the Django file in the correct place .) After decompression, run setup. py install, just like operating most Python libraries.

Here is how to install it on a Unix system:

  tar xzvf Django-*.tar.gz   cd Django-*   sudo python setup.py install 

7-Zip (http://www.djangoproject.com/r/7zip/ unzip To uncompress the .tar.gz file) is recommended on Windows. After decompression, start a DOS Shell (command prompt) with the administrator privilege, and then execute the following command in the directory named Django:

python setup.py install

If you are curious, Django will be installed in the 'site-package' directory of Your Python installation directory (from which Python looks for third-party libraries ). Normally, this directory is in/usr/lib/python2.4/site-packages.
Install Trunk

The latest and best django development version is called trunk, which can be obtained from the subversion of django. If you want to try it out or contribute code to django, you should install this version.

Subversion is a free open-source version control system similar to CVS. The Django development team uses it to manage updates to the Django code base. You can use the Subversion client to obtain the latest Django source code, and use local checkout to update the version of the local Django code at any time to obtain the latest updates and improvements made by Django developers.

Remember that even the trunk version is secure. Because many django developers use the trunk version on their official websites, they will ensure the stability of the trunk version.

Follow these steps to obtain the latest Django mainstream code:

  • Make sure that the Subversion client is installed. You can download this software from http://subversion.tigris.org/free and get outstanding documentation from http://svnbook.red-bean.com.
  • (If you are using Mac OS X 10.5 or an updated version, you are lucky to be able to install Django with Subversion. You can enter svn -- version on the terminal for verification.
  • Run the svn co http://code.djangoproject.com/svn/django/trunk djtrunk command to view the entity code.
  • Find your python site-packages directory. Generally, it is/usr/lib/python2.4/site-packages. If you are not sure, enter the following command:
  • Python-c 'import sys, pprint; pprint. pprint (sys. path )'
  • The above result will contain the directory of site-packages.
  • Under the site-packages directory, create a file django. pth and edit the file, which contains the full path profit of the djtrunk directory. The file contains the following lines:
/home/me/code/djtrunk
  • Add djtrunk/django/bin to the system variable PATH. This directory contains administrative tools like django-admin.py. This directory contains administrative tools such as django-admin.py

Tip:

If you haven't touched the. pth file before, you can get more relevant knowledge from the http://www.djangoproject.com/r/python/site-module.

After downloading from Subversion and executing the preceding steps, there is no need to execute python setup. py install again. You have already completed the installation manually!

Because the updates to Django's main code often include bug fixes and feature additions, if you are really fascinated, you may want to update it every short time. Run the svn update command in the djtrunk directory to perform updates. When you use this command, Subversion will contact the http://code.djangoproject.com to determine whether the code is updated, and then apply all the changes since the last update to the local code. That's simple.

Finally, if you use trunk, you need to know which trunk version is used. If you go to the community for help or provide improvement for the Django framework, it is very important to know the version number you are using. Therefore, when you go to the community for help or provide improvement suggestions for django, please remember the django version you are using. How do you know the django version you are using? Go to the ''djtrunk' directory, type svn info, and view the number followed by Revision: (version :) In the output information. After each update, the version number of Django increases progressively, including fixing bugs, adding features, improving documents, and other features. In some Django communities, the version number has even become a symbol of honor. I have used Djano since [writing a very low version number.
Test Django Installation

Let's take some time to test whether Django is successfully installed and works well. You can also get some clear feedback after installation. In Shell, change to another directory (not including Django directory) and input python to open the Python interactive interpreter. If the installation is successful, you can 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 interactively write Python programs. To start it, you only need to run the python command.

The Python example in the interactive interpreter runs through the entire book. You can use three greater than signs (>>>) to identify the example. The three greater than signs indicate the interactive prompt. If you want to copy an example from this book, do not copy the prompt.

In the interactive interpreter, multi-line declarations are filled with three vertices. 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

The three points that are inserted at the beginning of the new line are added by the Python Shell itself and do not belong to our input. However, they are included to pursue the correct output of the interpreter. If you copy our example to run it, do not copy these points.

Related Article

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: info-contact@alibabacloud.com 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.