一、在项目下面建一个reset.sh的文件
#!/bin/sh find . -path "*/migrations/*" -not -name "__init__.py" -delete && find . -name "db.sqlite3" -delete && sudo rm -rf media static && python manage.py makemigrations && python manage.py migrate && echo "\ from education.init import init_data;\ init_data.init();\ " | python manage.py shell python manage.py runserver
二、project---init---init_api.py
# coding: utf-8 from __future__ import unicode_literals from datetime import timedelta from apidocument.models import Api,ApiDetail,RequestExample,RequestParameter def apidocument_init(): User.objects.create_superuser(username='admin', password='admin123456', phone='13333333333', email='213@45.com') init_user() # client client = User() client.username = 'client' client.password = make_password('adminadmin') client.name = '用户' client.phone = '13322222222' client.email = '12553@456.com' client.save() for permission in Permission.objects.all(): client.user_permissions.add(permission) api1 = Api() api1.name = '小贴士' api1.save() api2 = Api() api2.name = '短信邮箱群发任务' api2.save() apidetail1 = ApiDetail() apidetail1.id = 4 apidetail1.url = 'http://127.0.0.1:8001/tip/sport/' apidetail1.method = "支持GET请求" apidetail1.format = "string" apidetail1.title = "获取sport或者safe标签的随机文字" apidetail1.api_id = 1 apidetail1.save() # apidetail2 = ApiDetail() apidetail2.id = 7 apidetail2.url = 'http://127.0.0.1:8001/tip/' apidetail2.method = "支持GET请求" apidetail2.format = "string" apidetail2.title = "获取随机文字" apidetail2.api_id = 1 apidetail2.save() apidetail3 = ApiDetail() apidetail3.id = 9 apidetail3.url = 'http://127.0.0.1:8001/tip/width/height/' apidetail3.method = "支持GET请求" apidetail3.format = "string" apidetail3.title = "获取随机可定制尺寸的图片" apidetail3.api_id = 1 apidetail3.save() apidetail4 = ApiDetail() apidetail4.id = 10 apidetail4.url = 'http://127.0.0.1:8001/tip/width/height/?image=number/' apidetail4.method = "支持GET请求" apidetail4.format = "string" apidetail4.title = "获取随机指定参数的随机自定制尺寸图片" apidetail4.api_id = 1 apidetail4.save() apidetail5 = ApiDetail() apidetail5.id = 11 apidetail5.url = 'http://127.0.0.1:8001/tip/width/height/sport/' apidetail5.method = "支持GET请求" apidetail5.format = "string" apidetail5.title = "获取sport或者safe标签的随机图片" apidetail5.api_id = 1 apidetail5.save() requestparameter1 = RequestParameter() requestparameter1.pname = "sport" requestparameter1.ptype = 'string' requestparameter1.need = "is" requestparameter1.summary = "显示sport标签的随机文字" requestparameter1.api_detail_id = 4 requestparameter1.save() requestparameter2 = RequestParameter() requestparameter2.pname = "/" requestparameter2.ptype = 'string' requestparameter2.need = "is" requestparameter2.summary = "显示随机文字" requestparameter2.api_detail_id = 7 requestparameter2.save() requestparameter3 = RequestParameter() requestparameter3.pname = "width" requestparameter3.ptype = 'int' requestparameter3.need = "is" requestparameter3.summary = "设置显示图片的宽度" requestparameter3.api_detail_id = 10 requestparameter3.save() requestparameter4 = RequestParameter() requestparameter4.pname = "height" requestparameter4.ptype = 'int' requestparameter4.need = "is" requestparameter4.summary = "设置显示图片的高度" requestparameter4.api_detail_id = 10 requestparameter4.save() requestparameter5 = RequestParameter() requestparameter5.pname = "width" requestparameter5.ptype = 'int' requestparameter5.need = "is" requestparameter5.summary = "设置显示图片的宽度" requestparameter5.api_detail_id = 11 requestparameter5.save() requestparameter6 = RequestParameter() requestparameter6.pname = "height" requestparameter6.ptype = 'int' requestparameter6.need = "is" requestparameter6.summary = "设置显示图片的高度" requestparameter6.api_detail_id = 11 requestparameter6.save() requestparameter7 = RequestParameter() requestparameter7.pname = "image" requestparameter7.ptype = 'int' requestparameter7.need = "is" requestparameter7.summary = "设置需要获取的图片ID" requestparameter7.api_detail_id = 10 requestparameter7.save() requestparameter8 = RequestParameter() requestparameter8.pname = "width" requestparameter8.ptype = 'int' requestparameter8.need = "is" requestparameter8.summary = "设置显示图片的宽度" requestparameter8.api_detail_id = 9 requestparameter8.save() requestparameter9 = RequestParameter() requestparameter9.pname = "height" requestparameter9.ptype = 'int' requestparameter9.need = "is" requestparameter9.summary = "设置显示图片的高度" requestparameter9.api_detail_id = 9 requestparameter9.save() requestparameter10 = RequestParameter() requestparameter10.pname = "sport" requestparameter10.ptype = 'string' requestparameter10.need = "is" requestparameter10.summary = "显示sport的随机文字" requestparameter10.api_detail_id = 11 requestparameter10.save() requestparameter11 = RequestParameter() requestparameter11.pname = "safe" requestparameter11.ptype = 'string' requestparameter11.need = "is" requestparameter11.summary = "显示safe标签的随机文字" requestparameter11.api_detail_id = 4 requestparameter11.save() requestparameter12 = RequestParameter() requestparameter12.pname = "safe" requestparameter12.ptype = 'string' requestparameter12.need = "is" requestparameter12.summary = "显示safe标签的随机图片" requestparameter12.api_detail_id = 11 requestparameter12.save() requestexample1 = RequestExample() requestexample1.requesturl = "http://127.0.0.1:8001/tip/" requestexample1.response = "牢记责任在心间,切莫追责悔已晚" requestexample1.api_detail_id = 7 requestexample1.save() requestexample2 = RequestExample() requestexample2.requesturl = "http://127.0.0.1:8001/tip/200/200/" requestexample2.response = '<img src="/media/tip/img/case1.jpg" width="200" height="200">' requestexample2.api_detail_id = 9 requestexample2.save() requestexample3 = RequestExample() requestexample3.requesturl = "http://127.0.0.1:8001/tip/100/50/?image=1/" requestexample3.response = '<img src="/media/tip/img/team2_F8NgOoS.jpg" width="100" height="50">' requestexample3.api_detail_id = 10 requestexample3.save() requestexample4 = RequestExample() requestexample4.requesturl = "http://127.0.0.1:8001/tip/sport/" requestexample4.response = "同心共筑中国梦想,合力共建网络强国" requestexample4.api_detail_id = 4 requestexample4.save() requestexample5 = RequestExample() requestexample5.requesturl = "http://127.0.0.1:8001/tip/100/300/sport/" requestexample5.response = '<img src="/media/tip/img/title.png" width="100" height="300">' requestexample5.api_detail_id = 11 requestexample5.save() requestexample6 = RequestExample() requestexample6.requesturl = "http://127.0.0.1:8001/tip/100/233/safe/" requestexample6.response = '<img src="/media/tip/img/team2.jpg" width="100" height="233">' requestexample6.api_detail_id = 11 requestexample6.save() requestexample7 = RequestExample() requestexample7.requesturl = "http://127.0.0.1:8001/tip/safe/" requestexample7.response = "打击互联网违法犯罪,共同抵制网络谣言" requestexample7.api_detail_id = 4 requestexample7.save()