How to build a python Django environment under Ubuntu 12.04

Source: Internet
Author: User

1. Check if Python is installed: Enter Python directly in the shell, and if Python is already installed, go to Python bash and see the version number (e.g. Python 2.7.3)

--Python should have been installed by default in Ubuntu

2. Install Django:

Install the official release: Download the installation package at http://www.djangoproject.com/download/and install it after unpacking:

sudo python setup.py install

Check if Django is installed: Enter in the Python shell:

>>> Import django>>> Django. VERSION

If the installation is successful, you should see the version number of the (1, 5, 1, ' final ', 0) style

3. Install the database (MySQL)

Input directly into the shell.

sudo apt-get install Mysql-server

You can install MySQL

The middle will prompt for a password, you can enter it or whatever it

Check if MySQL is installed:

Netstat-tap|grep MySQL

If installed successfully, you should be able to see TCP 0 0 Localhost:mysql *:* LISTEN such information

Then you can enter it in the shell.

Mysql-u root-p

Enter the MySQL shell (if you set a password at the time of installation, you need to enter a password) to perform various database operations

4. Installing the Python-mysql Adapter

sudo apt-get install Python-mysqldb

5. Configuring the Database in Django

1) Open settings.py to find such a paragraph:

12345678910 DATABASES ={    ‘default‘: {        ‘ENGINE‘‘django.db.backends.‘# Add ‘postgresql_psycopg2‘, ‘mysql‘, ‘sqlite3‘ or ‘oracle‘.        ‘NAME‘: ‘‘,                      # Or path to database file if using sqlite3.        ‘USER‘: ‘‘,                      # Not used with sqlite3.        ‘PASSWORD‘: ‘‘,                  # Not used with sqlite3.        ‘HOST‘: ‘‘,                      # Set to empty string for localhost. Not used with sqlite3.        ‘PORT‘: ‘‘,                      # Set to empty string for default. Not used with sqlite3.    }}

2) Configure ' ENGINE ' to django.db.backends.mysql

3) ' name ' is configured to select the DB name, such as MyDB

4) ' User ' PASSWORD ' enter the corresponding username and password

5) The configuration of ' HOST ' is doubtful, and I'll leave it empty as well.

6) test configuration:

Run the Python shell under the ' MySite ' project directory

Python manage.py Shell

Enter the following commands to test your database configuration:

>>> from django.db import connection>>> cursor = Connection.cursor ()

If no error message is displayed, your database configuration is correct. Otherwise, you should review the error message to correct the error.

Reference: http://www.djangobook.com/en/2.0/chapter05.html

Environment configuration almost like this, first write here, what problems to change

This article is from the "micro-hard programmer" blog, make sure to keep this source http://halolk.blog.51cto.com/6916369/1247795

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.