1、django-admin.py :执行文件
2、django-admin.py startproject XXX :创建项目,项目名是 XXX,会自动生成XXX项目,里面有manage.py文件,以及配置文件settings.py,eg:
python django-admin.py startproject MyTest
3、修改配置文件settings.py:
databases ={
'default' : {
'engine':
....
'user':
'password':
}
}
4、创建数据库:
数据库的名字要和上面配置中一样
5、object下创建app:
python manage.py startapp TestApp
6、生成操作数据库的models
python manage.py inspectdb >> models.py
7、数据库操作
例子:
apps = DbAppMain.objects.filter(pubtime__exact=pubtime).order_by('source_market', '-download_count').all()[ offset:offset+limit]
cnt = DbAppMain.objects.filter(pubtime__exact=pubtime).count()
try:
app = DbAppMain.objects.get(pk=appid)
except DbAppMain.DoesNotExist, e:
raise AppException(e)
cnt = DbAppMain.objects.filter(pubtime__exact=pubtime).count()
try:
app = DbAppMain.objects.get(pk=appid)
except DbAppMain.DoesNotExist, e:
raise AppException(e)