一.首先下载mysql—python模块,下载完毕之后会有一个MySQL-python-1.2.3.win32-py2.7.exe文件,点击安装一路next,ok。


二.编辑配置文件(setting.py)


 

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'blog',                     # Or path to database file if using sqlite3.
        # The following settings are not used with sqlite3:
        'USER': 'root',
        'PASSWORD': '',
        'HOST': '',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
        'PORT': '',                      # Set to empty string for default.
    }
}


注意:我的一个数据库叫名叫blog

 


三.django连接

1.在cmd命令框中进入project目录,输入 python manage.py shell

2.输入: >>>from django.db import connection

                >>>cursor=connection.cursor()


如果什么问题都没有,说明配置正确 。(别忘了开启你的mysql服务)


 

相关文章:

  • 2021-08-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-26
  • 2022-01-24
  • 2022-12-23
  • 2021-07-21
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-18
  • 2022-12-23
  • 2021-07-13
  • 2021-12-11
  • 2021-07-04
相关资源
相似解决方案