标签:tle img 令牌 软件 顺序 users .com 没有权限 size
200 OK - [GET]:服务器成功返回用户请求的数据,该操作是幂等的(Idempotent)。
201 CREATED - [POST/PUT/PATCH]:用户新建或修改数据成功。
202 Accepted - [*]:表示一个请求已经进入后台排队(异步任务)
204 NO CONTENT - [DELETE]:用户删除数据成功。
400 INVALID REQUEST - [POST/PUT/PATCH]:用户发出的请求有错误,服务器没有进行新建或修改数据的操作,该操作是幂等的。
401 Unauthorized - [*]:表示用户没有权限(令牌、用户名、密码错误)。
403 Forbidden - [*] 表示用户得到授权(与401错误相对),但是访问是被禁止的。
404 NOT FOUND - [*]:用户发出的请求针对的是不存在的记录,服务器没有进行操作,该操作是幂等的。
406 Not Acceptable - [GET]:用户请求的格式不可得(比如用户请求JSON格式,但是只有XML格式)。
410 Gone -[GET]:用户请求的资源被永久删除,且不会再得到的。
422 Unprocesable entity - [POST/PUT/PATCH] 当创建一个对象时,发生一个验证错误。
500 INTERNAL SERVER ERROR - [*]:服务器发生错误,用户将无法判断发出的请求是否成功。
更多看这里:http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
1
2
3
|
{ error: "Invalid API key" } |
1
2
3
4
5
6
|
GET / collection:返回资源对象的列表(数组) GET / collection / resource:返回单个资源对象 POST / collection:返回新生成的资源对象 PUT / collection / resource:返回完整的资源对象 PATCH / collection / resource:返回完整的资源对象 DELETE / collection / resource:返回一个空文档 |
1
2
3
4
5
6
|
{ "link" : { "rel" : "collection https://www.example.com/zoos" , "href" : "https://api.example.com/zoos" , "title" : "List of zoos" , "type" : "application/vnd.yourformat+json" }} |
摘自:http://www.ruanyifeng.com/blog/2014/05/restful_api.html
路由系统:
urlpatterns = [ url(r‘^users/$‘, views.Users.as_view()), url(r‘^users2/$‘, views.user2), ]
视图函数:
import json def user2(request): if request.method==‘GET‘: dic = {‘status‘:200,‘name‘: ‘lqz2‘, ‘age‘: 18} return HttpResponse(json.dumps(dic)) elif request.method==‘POST‘: dic = {‘status‘: 200, ‘msg‘: ‘修改成功‘} return JsonResponse(dic) class Users(View): def get(self, request): dic = {‘status‘:200,‘name‘: ‘lqz‘, ‘age‘: 18} return HttpResponse(json.dumps(dic)) def post(self, request): dic = {‘status‘: 200, ‘msg‘: ‘修改成功‘} return JsonResponse(dic)
标签:tle img 令牌 软件 顺序 users .com 没有权限 size
原文地址:https://www.cnblogs.com/di2wu/p/10126198.html