1.django-admin.py startproject mysite 开始一个项目,会初始化一些项目的结构文件 2.python manage.py runserver ip:port 如: python manage.py runserver 127.0.0.1:8080 利用ip能够访问不在同一个主机的数据库 3.python manage.py syncdb 注:会建立在setting.py下配置的INSTALL_APPS下的全部 app,建立其对应的数据表到指定的数据库,但只建立 不存在的表 4.python manage.py startapp polls 开启一个app叫polls,建立以下文件: polls/ __init__.py models.py tests.py view.py 5.python manage.py sql polls 将建立polls的模块的sql语句打印出来,但这不数据库中建立 对应的表,若要建立对应的表,须要先在INSTALL_APPS中配置 指定的app,而后运行同步数据库命令:python manage.py syncdb 6.python manage.py validate 检测模块中是否有错误 7.python manage.py sqlclear polls 打印出清楚模块polls的数据表的方法 8.python manage.py sqlindexes polls 打印出在模块polls中建立的索引 9.python manage.py sqlall polls 打印出全部的建立模块polls的sql语句,包括索引 10.须要在模块中写__unicode__()方法而不是__str__()方法 由于__str__()方法调用__unicode__()方法,而且__str__() 方法返回一个utf-8字符串,然而__unicode__()方法返回unicode 字符串,由于全部的从数据库中查出的数据都转换为unicode码,这 样,__unicode__()相似与unicode(p),转换为unicode码,__str__() 相似于encode('utf-8'),转换为utf-8 11.建立超级用户 manage.py createsuper --username=joe --email=joe@example.com 12.设置Django时区 修改TIME_ZONE='Asia/Shanghai',而后重启就ok了 13.查找已安装的模块的路径 python -c " import sys sys.path = sys.path[1:] import django print(django.__path__)"