- Django 1.0 Website Development
- Ayman Hourieh
- 1522字
- 2021-05-21 20:19:57
Installing the required software
Our development environment consists of Python, Django, and a database system. There are many different database systems available. In this book, we will be using a system known as SQLite. In the following section, we will see how to install the necessary software packages.
Installing Python
Django is written in Python, so the first step in setting up our development environment is to install Python. Python is available for a variety of operating systems, and installing it is not very different from installing any other software package. The procedure depends on your operating system.
You will need a recent version of Python. Django requires Python 2.3 or higher. The latest version of Python, at the time of writing, is 2.5.
We will now look at the installation process for each operating system.
Python has a standard installer for Windows users. You will need to go to http://www.python.org/download/ and download the latest version of Python. Next, double-click the .exe
file and follow the installation instructions. The graphical installer will guide you through the installation process and create shortcuts to Python executables in the Start menu.
Once the installation has been done, we need to add the Python directory to the system path so that we can access Python while using the command prompt. To do this, open the Control Panel, double-click on the System icon, go to the Advanced tab, and click the Environment Variables button. A new dialog box will open. Select the variable Path from the System variable section, and append the path where you have installed Python. (The default path is usually c:\PythonXX
, where XX
is your Python version. So if you have Python 2.5, you should append c:\Python25
.) Don't forget to separate the new path from the one before it with a semicolon.
If you want to test your installation, open the Run dialog, type python
, and hit Enter. The Python interactive shell should open.
If you are using Linux or UNIX, the chances are that you already have Python installed. To check, open a terminal, type python
and hit Enter. If you see the Python interactive shell, then you already have Python installed:
Python 2.5.1 (r251:54863, May 2 2007, 16:56:35) [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>
The first line of the output indicates the version installed on your system (2.5.1 here).
If you receive an error message instead of seeing the output, or have an old version of Python, you should read on.
UNIX and Linux users are recommended to install and update Python through the system package manager. Although the actual details vary from system to system, it won't be any different from installing any other package.
For APT-based Linux distributions (such as Debian and Ubuntu), open a terminal and type:
$ sudo apt-get update $ sudo apt-get install python
Or if you have the Synaptic Package Manager, simply search for Python, mark its package for installation, and click on Apply.
Users of other Linux distributions are recommended to check their system documentation for information on how to use the package manager to install packages.
Mac OS X comes pre-installed with Python. However, due to Apple's release cycle, it's often an old version. If you start the Python interactive shell and find a version older than 2.3, you should visit this URL: http://www.python.org/download/mac/ and download the most recent installer for your version of Mac OS X.
Now that Python is up and running, we are almost ready. Next, we will install Django and make sure that we have a database system.
Installing Django
Installing Django is very easy, but the steps required for its installation depend on your operating system. Since Python is a platform-independent language, Django has one package that works everywhere regardless of your operating system.
To download Django, head to http://www.djangoproject.com/download/, and grab the latest official version. The code in this book was developed on Django 1.0 (the latest version at the time of writing), but most of it should run on the later official releases too. Next, follow the instructions related to your platform.
After you download the Django archive, extract it to the C drive and open a command prompt (by clicking on Start, and then Accessories). Change the current directory to where you extracted Django by issuing the following command, where x.xx is your Django version:
c:\>cd c:\Django-x.xx
Next, install Django by running the following command (for which you will need administrative privileges):
c:\Django-x.xx>python setup.py install
If these instructions do not work, you can manually copy the django
folder in the archive to the Lib | site-packages folder located in the Python installation directory. This will do the job of running the setup.py
install command.
Note
If you do not have a program to handle the .tar.gz
files on your system, I recommend using 7-Zip, which is free and available at http://www.7-zip.org/.
The last step is copying the django-admin.py
file from Django-x.xx | django | bin to somewhere in your system path, such as c:\windows
or the folder where you installed Python.
Once this has been done, you can safely remove the c:\Django-x.xx
folder, because it is no longer needed.
That's it. 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.
Installation instructions for all UNIX and Linux systems are the same. You need to run the following commands in the directory where the Django-x.xx.tar.gz
archive is located. These commands will extract the archive and install Django for you:
$ tar xfz Django-x.xx.tar.gz $ cd Django-x.xx $ sudo python setup.py install
These instructions should work on any UNIX or Linux system as well as on Mac OS X. However, it may be easier to install Django through your system's package manager if it has a package for Django. Ubuntu has one, so to install Django on Ubuntu, simply look for the package python-django
in Synaptic, or run the following command:
$ sudo apt-get install python-django
You can test your installation by running this command:
$ django-admin.py --version
If you are using the python-django
package in Ubuntu, the command will be slightly different. It won't contain the .py
extension. Keep this in mind because you will be using the django-admin.py
again later on.
$ django-admin --version
If you see the current version of Django printed on the screen, then everything is set.
Installing a database system
While Django does not require a database to function, the application that we are going to develop does. So in the last step of software installation, we are going to make sure that we have a database system for handling our data.
It is worth noting that Django supports several database engines: MySQL, PostgreSQL, MS SQL Server, Oracle, and SQLite. Interestingly, you only need to learn one API in order to use any of these database systems. This is possibly because of Django's database layer, which abstracts access to the database system. We will learn about this later. For now you only need to know that regardless of the database system you choose, you will be able to run the Django applications developed in this book (or elsewhere) without modification.
If you have Python 2.5 or higher, you won't need to install anything as Python 2.5 comes with the SQLite database management system contained in a module named sqlite3
. Unlike client-server database systems, SQLite does not require a resident process in memory. It stores the database in a single file, which makes it ideal for our development environment. Therefore, throughout this book, we will be using SQLite in our examples. Of course, you are free to use your preferred database management system. We can tell Django what database system to use by editing a configuration file, as we will see in later sections. It is also worth noting that if you want to use MySQL, you will need to install MySQLdb, the MySQL driver for Python.
If you don't have Python 2.5, you can manually install the python module for SQLite by downloading it from http://www.pysqlite.org/ (for Windows users) or through your package manager (for UNIX and Linux users).
Note
Django comes with its own web server, and we will use it during the development phase because it is lightweight and comes pre-configured for Django. However, Django does support Apache and other popular web servers such as Lighttpd. We will see how to configure Django for Apache when we prepare our application for deployment later in this book.
The same applies to the database manager. During the development phase, we will use SQLite because it is easy to set up. But when we deploy the application, we will switch to a database server such as MySQL.
As I said earlier, regardless of what components we use, our code will stay the same. Django handles all the communication with the web and database servers for us.
- 常用工具軟件案例教程
- Drools規則引擎技術指南
- PPT 2016幻燈片設計與制作從入門到精通
- ADOBE FLASH PROFESSIONAL CS6 標準培訓教材
- 剪映視頻后期剪輯零基礎入門到精通
- ASP.NET 3.5 Social Networking
- Photoshop CS6案例教程(第3版)
- NetSuite OneWorld Implementation 2011 R2
- Premiere Pro基礎與實戰教程
- Altium Designer 20 中文版從入門到精通
- MooTools 1.2 Beginner's Guide
- Cinema 4D/After Effects印象 影視包裝技法精解基礎篇
- HBase企業應用開發實戰
- Creo 4.0中文版基礎教程
- 電磁場數值計算及基于FreeFEM的編程實現