Django Web Development "2" Django Getting Started

Source: Internet
Author: User
Tags django website

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

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.