region_comments = models.CharField(‘说明’,max_length=250, blank=True)
增加参数blank,值为True,不设置则默认为必填
region_comments = models.CharField(‘说明’,max_length=250, blank=True)
增加参数blank,值为True,不设置则默认为必填
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': '数据库名字', 'USER': '数据库用户', 'PASSWORD': '数据库密码', 'HOST': '127.0.0.1', 'PORT': '3306', 'OPTIONS': { 'charset' : 'utf8', 'use_unicode' : True, # 'autocommit': True, } } }
import pymysql pymysql.install_as_MySQLdb()
修改settings.py
LANGUAGE_CODE = ‘zh-hans’
修改时区
TIME_ZONE = ‘Asia/Shanghai’
USE_TZ = False
ubuntu合两个版本的python ,同时又python2 和python3
当前系统版本
terry@vUBox:~$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04.1 LTS Release: 16.04 Codename: xenial
1.启动python2
terry@vUBox:~$ python Python 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609] on linux2 Type "help", "cophuyright", "credits" or "license" for more information. >>>
2.如果要启动python3
输入pyhthon3
terry@vUBox:~$ python3 Python 3.5.2 (default, Nov 17 2016, 17:05:23) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>>
安装django
python2 使用django
sudo apt-get install python-django -y
如果要在python3 中调用django,django安装命令
sudo apt-get install python3-django -y
terry@vUBox:~$ python3 Python 3.5.2 (default, Nov 17 2016, 17:05:23) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import django >>> print(django.get_version()) 1.8.7 >>>