自学最困难的,就是越到后面会觉得越难。跟改革一样,进入了深水区,越来越难了,这时候需要更大的毅力和耐力把它扛下来。
这里得先感谢下白月黑羽的教程,免费的文本教程和视频教程,讲得非常细。一步一步跟着老师来做,就能实现,学下来会少走不少弯路。
视频路径:https://www.bilibili.com/video/BV1AE41117Up?p=16&spm_id_from=pageDriver
文本路径:http://www.python3.vip/tut/webdev/django/07/
1. 在bysms文件下,建立mgr程序包
2. 新建customer.py 在customer.py 里面建立dispatcher 函数
from django.http import JsonResponse
import json
from common.models import Customer
def dispatcher(request):
if request.method =="GET":
request.params=request.GET
elif request.method in['POST','PUT','DELETE']:
request.params=json.loads(request.body)
action=request.params['action']
if action=='list_customer':
return listcustomer(request)
elif action=='add_customer':
return addcustomer(request)
elif action=='modify_customer':
return modifycustomer(request)
elif action=='del_customer':
return delcustomer(request)
else:
return JsonResponse({'ret':1,'msg':'不支持'})
3. 在路由表中做设置,从接口文件customer过来的文件,用dispatcher函数进行处理。
4. 在总的路由表urls.py中进行设置
path('/api/mgr', include('mgr.urls')),
5. 在mgr里面的urls.py里面加入代码
6. 完成客户添加,修改,删除的程序部分
7. 取消CSRF校验
8. 启动服务器python manage.py runserver 80
9. 输入网址http://localhost/mgr/index.html