Django 创建APP简单步骤

时间:2021-03-02 18:53:04

yum install epel-release
yum install python34
yum install python-pip
pip install django

django-admin startproject projectName

django-admin startapp appName

配置mysql:

CREATE DATABASE databaseName CHARACTER SET utf8; //创建数据库,指定utf8支持中文字符

pip3 install pymsql

站点__init__.py中添加

import pymysql
pymysql.install_as_MySQLdb()

settings.py中配置:

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'databaseName', 
'USER':'userName',
'PASSWORD':'passwd',
'HOST':'',
'PORT':'',
}
}

支持中文:

LANGUAGE_CODE = 'zh-Hans'#'en-us'

TIME_ZONE = 'Asia/Shanghai'#'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

执行manage.py migrate

成功就OK了。

如果系统中有python2.X上述步骤会报错,pip 会把django安装到python2.X下。

安装pip3

pip3 install django

pip3安装参考http://www.cnblogs.com/vawter/p/6254170.html