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