Configuring the development environment
1. Install Python, I am using the CentOS 6.0,python version of 2.6.6
2. Install the Django,django version 1.3.5
After downloading the corresponding version on the Django website, unzip the package, go to the archive directory, run
Install
You can check if Django is installed correctly with the following command.
django-admin.py--version
If the results output a Django version, the installation succeeds.
3. Install the database, use MySQL here, please install it yourself.
Create the first project
Enter the following command on the Linux terminal to create the Django_bookmarks project.
$ django-admin.py Startproject Django_bookmarks
This command creates a folder named Django_bookmarks in the current directory, with the following structure in the folder:
django_bookmarks/ __init__.py manage.py settings.py urls.py
__init__.py that this folder is a Python package, manage.py is used to manage the entire project, and its role is similar to django-admin.py. settings.py is a configuration file for the entire project, and url.py is used to configure the distribution of URLs.
Database configuration
Open settings.py, configure the data, and the options in settings.py for data configuration are as follows:
' MySQL ' 'bookmarksdb' root' localhost '3306 '
Because we use the MySQL database, the value of Database_engine is set to MySQL, and our database name makes it the Bookmarksdb,mysql default port of 3306. After modifying the above configuration, run the following code to initialize the database.
Python manage.py syncdb
Execute the above code, and Django will automatically create the corresponding data table.
Start the server
Django itself provides a server for testing the development environment. The advantage of this server is that it will restart automatically whenever the code is modified.
Start the server by using the following command:
$ python manage.py runserver
Then open the browser and enter
$ python manage.py runserver
Without an accident, a welcome message will be output. The default Django uses port 8000 to specify the port and the listening IP address when running manage.py. For example:
$ python manage.py runserver 0.0.0.0:9000
The server above listens on port 9000 for all IP addresses.
Django Web Development "2" Django Getting Started