Django初始化

1、进入虚拟环境并安装Django

# workon wechat
# pip install --upgrade django

2、生成文件

# django-admin startproject weixin
# django-admin startapp wechat

3、数据库

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'weixin',
        'USER': 'fun',
        'PASSWOED': 'xxxxxx',
        'HOST': 'localhost',
        'PORT': '3306',
        'OPTIONS': {
            'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
        },
    }
}

4、创建数据库并授权

> create database weixin;
> grant all on weixin.* to 'fun'@'localhost' identified by 'xxxxxx';
> flush privileges;

5、如果出现错误:django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.

在weixin/__init__.py文件中添加

import pymysql
pymysql.install_as_MySQLdb()
 



猜你喜欢

转载自blog.csdn.net/fanper/article/details/80950081