第25月第17天 django rest framwork authentication /tmp/mysql.sock
1.authentication
https://www.django-rest-framework.org/api-guide/authentication/#authentication
2.django-rest-framework-jwt
curl -X POST -H "Content-Type: application/json" -d '{"username":"admin","password":"password123"}' http://localhost:8000/api-token-auth/
http://getblimp.github.io/django-rest-framework-jwt/#installation
3.djoser
'rest_framework', 'rest_framework.authtoken', 'djoser',
You need to add 'rest_framework.authtoken' to your INSTALLED_APPS
curl -X POST http://127.0.0.1:8088/auth/token/login/ --data 'username=djoser&password=djoser'
curl -X POST http://127.0.0.1:8000/api/v1/auth/token/login/ -H "Content-Type: application/json" --data '{"username":"aa123456","password":"aa123456"}'
curl -X POST http://localhost:8000/api/v1/owner/object/all -H "Content-Type: application/json" -H 'Authorization: Token 'baa10f5da4f6e775fd50ca412be4bd828bd5c0d4 --data '{"username":"aa123456","password":"aa123456"}'
https://djoser.readthedocs.io/en/stable/sample_usage.html
pip install httpie
http GET http://localhost:8000/api/v1/article Authorization:" Token baa10f5da4f6e775fd50ca412be4bd828bd5c0d4"
echo '{"author":"aa123456","title":"11114","content":"11114"}' | http POST http://localhost:8000/api/v1/article/add Authorization:" Token baa10f5da4f6e775fd50ca412be4bd828bd5c0d4"
上传文件
http -f POST http://localhost:8000/uploadfiles/ Authorization:" JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjozLCJ1c2VybmFtZSI6IjE4MTExMTExMTEyIiwiZXhwIjoxNTQwNTE1NjA5LCJlbWFpbCI6bnVsbH0.LGcL0NUF1EzJkdLApio15eTGQ6GuYYYl4qekZMoVrcI" file@../aa.png
https://httpie.org/doc#non-string-json-fields
4.获取用户post json数据
data=JSONParser().parse(request) print (data["username"])
https://blog.csdn.net/Oudelosiki/article/details/79827920
5.xampp mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'
ln -s /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock /tmp/mysql.sock
6.上传文件重命名
https://www.cnblogs.com/zhaoyingjie/p/6894979.html