To make cross-domain requests, so the first cross-domain configuration
The connection configuration information stored in the database in settings.py, Django using default initial configuration database sqlite
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } }
Use MySQL database first need to install the driver
pip install PyMySQL
We want to use the mysql database, the databases in settings.py 'ENGINE': 'django.db.backends.sqlite3',
Changed'ENGINE': 'django.db.backends.mysql',
Add the following statement in the project of the same name __init__.py file in a subdirectory of Django
from pymysql import install_as_MySQLdb
install_as_MySQLdb()
3. Modify the configuration information DATABASES
= DATABASES { ' default ' : { ' ENGINE ' : ' django.db.backends.mysql ' , ' the HOST ' : ' 127.0.0.1 ' , # database host ' PORT ' : 3306, # database port ' the USER ' : ' the root ' , # database user name ' PASSWORD ' : ' MySQL ' , # Database user password 'NAME ' : ' django_demo ' # database name } }