As a little white with Python, starting to learn Django is doomed to a long way, documenting the learning process problems and solutions.
Thanks to the selfless dedication of the "self-Improvement Academy", after installing Django 1.9.12 in the tutorial, try to create a new project with Python manage.py Startapp App-name has been unable to build the app. The last line of the error is "Django.core.exceptions.ImproperlyConfigured:Error loading either Pysqlite2 or Sqlite3 modules (tried in or Der): No module named _sqlite3 "As a small white, direct Baidu a little bit of this sentence, found no SQLite database. No, I'm supposed to be connected to the MySQL database.
Continue Baidu.
The settings for the database in Django are in the settings.py file. Open the file found inside the main configuration are linked to the official website, decisive officer NET, find the database configuration as follows:
# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases
DATABASES = {
' Default ': {
' ENGINE ': ' Django.db.backends.sqlite3 ',
' NAME ': Os.path.join (Base_dir, ' db.sqlite3 '),
}
}
According to the guidance of the official website, the database engine was changed to MySQL, and the relevant configuration.
DATABASES = {
' Default ': {
' ENGINE ': ' Django.db.backends.mysql ',
' NAME ': ' * * * ', #数据库名
' USER ': ' * * * ', #数据库用户名
' PASSWORD ': ' ******* ', #数据库密码
' HOST ': ' 127.0.0.1 ',
' PORT ': ' 3306 ',
}
}
After backing up the original file and modifying it, try to execute Python manage.py startapp app-name continue to error .... "No module named MySQLdb". Well, I've already installed the Pymysql, or I'll put a mysqldb on it. Various YUM/PIP installations are unsuccessful. Not very patient, mainly is the Pymysql is the MYSQLDB upgrade version, should be able to use only.
Continue Baidu.
Find the method.
In the site's __init__.py file, add the following code:
1 Import pymysql2 pymysql.install_as_mysqldb ()
After configuration, execute Python manage.py startapp app-name no longer error, open folder, app has been established. Problem solving.
Django Learning (1)--python manage.py startapp app-name new app error problem