python3 connection with Django database: Error loading MySQLdb module: No module named 'MySQLdb'
In python2 using pip install mysql-python
for installation and connection of MySQL database, using import MySQLdb
for use
In python3, changing the link libraries, to the pymysql
library, the use of pip install pymysql
the installation, can be used directly into
But in Django, use when connecting to the database is MySQLdb library, which will be reported in cooperation with the following error in the python3
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'
Solution: Add the following code to the __init__.py file.
import pymysql
pymysql.install_as_MySQLdb()
python3 connection with Django database: Invalid HTTP_HOST header: '17 .16.22.13: 8000 to ALLOWED_HOSTS 'You may need to add '17 .16.22.13.'.
Solution: Modify the ALLOWED_HOSTS in setting.py
ALLOWED_HOSTS = ['*']
python3 connection with the Django database: display can not load sqllite3
# Database # https://docs.djangoproject.com/en/1.8/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'archer', #database name 'USER': 'archer_rw', 'PASSWORD': 'archer_rw', 'HOST': '127.0.0.1', 'PORT': '3306' } }