python3+django安装mysql

2019-01-16  本文已影响14人  望月成三人

创建一个项目

新建数据库

DATABASES = {
    'default': {
         'ENGINE': 'django.db.backends.mysql',
        'NAME': 'test', #数据库名字
        'USER': 'root',
        'PASSWORD': '',
        'HOST': '127.0.0.1',
        'PORT': '3306',
    }
}
pip install PyMySQL

找到mysite/mysite/init.py,在里面输入以下内容并保存:

import pymysql
pymysql.install_as_MySQLdb()
python manage.py runserver

就会看到如下所示:

System check identified no issues (0 silenced).

You have 13 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
February 06, 2017 - 14:47:11
Django version 1.10.5, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Of course, you haven't actually done any work yet. Next, start your first app by running python manage.py startapp [app_label].
You're seeing this message because you have DEBUG = True in your Django settings file and you haven't configured any URLs. Get to work!
DEBUG = False
ALLOWED_HOSTS = ['*']

最后再次运行:

python manage.py runserver

上一篇下一篇

猜你喜欢

热点阅读