目录

一、基础

1.1.安装

两种方式:

  1. pip install djangorestframework

1.2.需要先了解的一些知识

理解下面两个知识点非常重要,django-rest-framework源码中到处都是基于CBV和面向对象的封装

(1)面向对象封装的两大特性

  1. 把同一类方法封装到类中
  2.  
  3. 将数据封装到对象中

(2)CBV

基于反射实现根据请求方式不同,执行不同的方法

原理:url-->view方法-->dispatch方法(反射执行其它方法:GET/POST/PUT/DELETE等等)

二、简单实例

2.1.settings

先创建一个project和一个app(我这里命名为API)

首先要在settings的app中添加

  1. INSTALLED_APPS = [
  2. 'rest_framework',
  3. ]

2.2.url

  1. from django.contrib import admin
  2. from django.urls import path
  3. from API.views import AuthView
  4.  
  5. urlpatterns = [
  6. path('admin/', admin.site.urls),
  7. path('api/v1/auth/',AuthView.as_view()),
  8. ]

2.3.models

一个保存用户的信息

一个保存用户登录成功后的token

  1. from django.db import models
  2.  
  3. class UserInfo(models.Model):
  4. USER_TYPE = (
  5. (1,'普通用户'),
  6. (2,'VIP'),
  7. (3,'SVIP')
  8. )
  9.  
  10. user_type = models.IntegerField(choices=USER_TYPE)
  11. username = models.CharField(max_length=32)
  12. password = models.CharField(max_length=64)
  13.  
  14. class UserToken(models.Model):
  15. user = models.OneToOneField(UserInfo,on_delete=models.CASCADE)
  16. token = models.CharField(max_length=64)

2.4.views

用户登录(返回token并保存到数据库)

  1. from django.shortcuts import render
  2. from django.http import JsonResponse
  3. from rest_framework.views import APIView
  4. from API import models
  5.  
  6. def md5(user):
  7. import hashlib
  8. import time
  9. #当前时间,相当于生成一个随机的字符串
  10. ctime = str(time.time())
  11. m = hashlib.md5(bytes(user,encoding='utf-8'))
  12. m.update(bytes(ctime,encoding='utf-8'))
  13. return m.hexdigest()
  14.  
  15. class AuthView(object):
  16. def post(self,request,*args,**kwargs):
  17. ret = {'code':1000,'msg':None}
  18. try:
  19. user = request._request.POST.get('username')
  20. pwd = request._request.POST.get('password')
  21. obj = models.UserInfo.objects.filter(username=user,password=pwd).first()
  22. if not obj:
  23. ret['code'] = 1001
  24. ret['msg'] = '用户名或密码错误'
  25. #为用户创建token
  26. token = md5(user)
  27. #存在就更新,不存在就创建
  28. models.UserToken.objects.update_or_create(user=obj,defaults={'token':token})
  29. ret['token'] = token
  30. except Exception as e:
  31. ret['code'] = 1002
  32. ret['msg'] = '请求异常'
  33. return JsonResponse(ret)

2.5.利用postman发请求

如果用户名和密码正确的话  会生成token值,下次该用户再登录时,token的值就会更新

数据库中可以看到token的值

当用户名或密码错误时,抛出异常

三、添加认证

基于上面的例子,添加一个认证的类

3.1.url

  1. path('api/v1/order/',OrderView.as_view()),

3.2.views

  1. from django.shortcuts import render,HttpResponse
  2. from django.http import JsonResponse
  3. from rest_framework.views import APIView
  4. from API import models
  5. from rest_framework.request import Request
  6. from rest_framework import exceptions
  7. from rest_framework.authentication import BasicAuthentication
  8.  
  9. ORDER_DICT = {
  10. 1:{
  11. 'name':'apple',
  12. 'price':15
  13. },
  14. 2:{
  15. 'name':'dog',
  16. 'price':100
  17. }
  18. }
  19.  
  20. def md5(user):
  21. import hashlib
  22. import time
  23. #当前时间,相当于生成一个随机的字符串
  24. ctime = str(time.time())
  25. m = hashlib.md5(bytes(user,encoding='utf-8'))
  26. m.update(bytes(ctime,encoding='utf-8'))
  27. return m.hexdigest()
  28.  
  29. class AuthView(object):
  30. '''用于用户登录验证'''
  31. def post(self,request,*args,**kwargs):
  32. ret = {'code':1000,'msg':None}
  33. try:
  34. user = request._request.POST.get('username')
  35. pwd = request._request.POST.get('password')
  36. obj = models.UserInfo.objects.filter(username=user,password=pwd).first()
  37. if not obj:
  38. ret['code'] = 1001
  39. ret['msg'] = '用户名或密码错误'
  40. #为用户创建token
  41. token = md5(user)
  42. #存在就更新,不存在就创建
  43. models.UserToken.objects.update_or_create(user=obj,defaults={'token':token})
  44. ret['token'] = token
  45. except Exception as e:
  46. ret['code'] = 1002
  47. ret['msg'] = '请求异常'
  48. return JsonResponse(ret)
  49.  
  50. class Authentication(APIView):
  51. '''认证'''
  52. def authenticate(self,request):
  53. token = request._request.GET.get('token')
  54. token_obj = models.UserToken.objects.filter(token=token).first()
  55. if not token_obj:
  56. raise exceptions.AuthenticationFailed('用户认证失败')
  57. #在rest framework内部会将这两个字段赋值给request,以供后续操作使用
  58. return (token_obj.user,token_obj)
  59.  
  60. def authenticate_header(self, request):
  61. pass
  62.  
  63. class OrderView(APIView):
  64. '''订单相关业务'''
  65.  
  66. authentication_classes = [Authentication,] #添加认证
  67. def get(self,request,*args,**kwargs):
  68. #request.user
  69. #request.auth
  70. ret = {'code':1000,'msg':None,'data':None}
  71. try:
  72. ret['data'] = ORDER_DICT
  73. except Exception as e:
  74. pass
  75. return JsonResponse(ret)

3.3用postman发get请求

请求的时候没有带token,可以看到会显示“用户认证失败”

这样就达到了认证的效果,django-rest-framework的认证是怎么实现的呢,下面基于这个例子来剖析drf的源码。

四、drf的认证源码分析

源码流程图

请求先到dispatch

dispatch()主要做了两件事

  • 封装request
  • 认证  

具体看我写的代码里面的注释

  1. def dispatch(self, request, *args, **kwargs):
  2. """
  3. `.dispatch()` is pretty much the same as Django's regular dispatch,
  4. but with extra hooks for startup, finalize, and exception handling.
  5. """
  6. self.args = args
  7. self.kwargs = kwargs
  8. #对原始request进行加工,丰富了一些功能
  9. #Request(
  10. # request,
  11. # parsers=self.get_parsers(),
  12. # authenticators=self.get_authenticators(),
  13. # negotiator=self.get_content_negotiator(),
  14. # parser_context=parser_context
  15. # )
  16. #request(原始request,[BasicAuthentications对象,])
  17. #获取原生request,request._request
  18. #获取认证类的对象,request.authticators
  19. #1.封装request
  20. request = self.initialize_request(request, *args, **kwargs)
  21. self.request = request
  22. self.headers = self.default_response_headers # deprecate?
  23.  
  24. try:
  25. #2.认证
  26. self.initial(request, *args, **kwargs)
  27.  
  28. # Get the appropriate handler method
  29. if request.method.lower() in self.http_method_names:
  30. handler = getattr(self, request.method.lower(),
  31. self.http_method_not_allowed)
  32. else:
  33. handler = self.http_method_not_allowed
  34.  
  35. response = handler(request, *args, **kwargs)
  36.  
  37. except Exception as exc:
  38. response = self.handle_exception(exc)
  39.  
  40. self.response = self.finalize_response(request, response, *args, **kwargs)
  41. return self.response

4.1.reuqest

(1)initialize_request()

可以看到initialize()就是封装原始request

  1. def initialize_request(self, request, *args, **kwargs):
  2. """
  3. Returns the initial request object.
  4. """
  5. parser_context = self.get_parser_context(request)
  6.  
  7. return Request(
  8. request,
  9. parsers=self.get_parsers(),
  10. authenticators=self.get_authenticators(), #[BasicAuthentication(),],把对象封装到request里面了
  1.        negotiator=self.get_content_negotiator(), parser_context=parser_context )

(2)get_authenticators()

通过列表生成式,返回对象的列表

  1. def get_authenticators(self):
  2. """
  3. Instantiates and returns the list of authenticators that this view can use.
  4. """
  5. return [auth() for auth in self.authentication_classes]

(3)authentication_classes

APIView里面有个  authentication_classes   字段

可以看到默认是去全局的配置文件找(api_settings)

  1. class APIView(View):
  2.  
  3. # The following policies may be set at either globally, or per-view.
  4. renderer_classes = api_settings.DEFAULT_RENDERER_CLASSES
  5. parser_classes = api_settings.DEFAULT_PARSER_CLASSES
  6. authentication_classes = api_settings.DEFAULT_AUTHENTICATION_CLASSES
  7. throttle_classes = api_settings.DEFAULT_THROTTLE_CLASSES
  8. permission_classes = api_settings.DEFAULT_PERMISSION_CLASSES
  9. content_negotiation_class = api_settings.DEFAULT_CONTENT_NEGOTIATION_CLASS
  10. metadata_class = api_settings.DEFAULT_METADATA_CLASS
  11. versioning_class = api_settings.DEFAULT_VERSIONING_CLASS

4.2.认证

self.initial(request, *args, **kwargs)

  1. def dispatch(self, request, *args, **kwargs):
  2. """
  3. `.dispatch()` is pretty much the same as Django's regular dispatch,
  4. but with extra hooks for startup, finalize, and exception handling.
  5. """
  6. self.args = args
  7. self.kwargs = kwargs
  8. #对原始request进行加工,丰富了一些功能
  9. #Request(
  10. # request,
  11. # parsers=self.get_parsers(),
  12. # authenticators=self.get_authenticators(),
  13. # negotiator=self.get_content_negotiator(),
  14. # parser_context=parser_context
  15. # )
  16. #request(原始request,[BasicAuthentications对象,])
  17. #获取原生request,request._request
  18. #获取认证类的对象,request.authticators
  19. #1.封装request
  20. request = self.initialize_request(request, *args, **kwargs)
  21. self.request = request
  22. self.headers = self.default_response_headers # deprecate?
  23.  
  24. try:
  25. #2.认证
  26. self.initial(request, *args, **kwargs)
  27.  
  28. # Get the appropriate handler method
  29. if request.method.lower() in self.http_method_names:
  30. handler = getattr(self, request.method.lower(),
  31. self.http_method_not_allowed)
  32. else:
  33. handler = self.http_method_not_allowed
  34.  
  35. response = handler(request, *args, **kwargs)
  36.  
  37. except Exception as exc:
  38. response = self.handle_exception(exc)
  39.  
  40. self.response = self.finalize_response(request, response, *args, **kwargs)
  41. return self.response

(1)initial()

主要看 self.perform_authentication(request),实现认证

  1. def initial(self, request, *args, **kwargs):
  2. """
  3. Runs anything that needs to occur prior to calling the method handler.
  4. """
  5. self.format_kwarg = self.get_format_suffix(**kwargs)
  6.  
  7. # Perform content negotiation and store the accepted info on the request
  8. neg = self.perform_content_negotiation(request)
  9. request.accepted_renderer, request.accepted_media_type = neg
  10.  
  11. # Determine the API version, if versioning is in use.
  12. version, scheme = self.determine_version(request, *args, **kwargs)
  13. request.version, request.versioning_scheme = version, scheme
  14.  
  15. # Ensure that the incoming request is permitted
  16. #3.实现认证
  17. self.perform_authentication(request)
  18. self.check_permissions(request)
  19. self.check_throttles(request)

(2)perform_authentication()

调用了request.user

  1. def perform_authentication(self, request):
  2. """
  3. Perform authentication on the incoming request.
  4.  
  5. Note that if you override this and simply 'pass', then authentication
  6. will instead be performed lazily, the first time either
  7. `request.user` or `request.auth` is accessed.
  8. """
  9. request.user

(3)user

request.user的request的位置

点进去可以看到Request有个user方法,加 @property 表示调用user方法的时候不需要加括号“user()”,可以直接调用:request.user

  1. @property
  2. def user(self):
  3. """
  4. Returns the user associated with the current request, as authenticated
  5. by the authentication classes provided to the request.
  6. """
  7. if not hasattr(self, '_user'):
  8. with wrap_attributeerrors():
  9. #获取认证对象,进行一步步的认证
  10. self._authenticate()
  11. return self._user

(4)_authenticate()

循环所有authenticator对象

  1. def _authenticate(self):
  2. """
  3. Attempt to authenticate the request using each authentication instance
  4. in turn.
  5. """
  6. #循环认证类的所有对象
  7. #执行对象的authenticate方法
  8. for authenticator in self.authenticators:
  9. try:
  10. #执行认证类的authenticate方法
  11. #这里分三种情况
  12. #1.如果authenticate方法抛出异常,self._not_authenticated()执行
  13. #2.有返回值,必须是元组:(request.user,request.auth)
  14. #3.返回None,表示当前认证不处理,等下一个认证来处理
  15. user_auth_tuple = authenticator.authenticate(self)
  16. except exceptions.APIException:
  17. self._not_authenticated()
  18. raise
  19.  
  20. if user_auth_tuple is not None:
  21. self._authenticator = authenticator
  22. self.user, self.auth = user_auth_tuple
  23. return
  24.  
  25. self._not_authenticated()

返回值就是例子中的:

  1. token_obj.user-->>request.user
  1. token_obj-->>request.auth
  1. #在rest framework内部会将这两个字段赋值给request,以供后续操作使用
  2. return (token_obj.user,token_obj) #例子中的return

当都没有返回值,就执行self._not_authenticated(),相当于匿名用户,没有通过认证

  1. def _not_authenticated(self):
  2. """
  3. Set authenticator, user & authtoken representing an unauthenticated request.
  4.  
  5. Defaults are None, AnonymousUser & None.
  6. """
  7. self._authenticator = None
  8.  
  9. if api_settings.UNAUTHENTICATED_USER:
  10. self.user = api_settings.UNAUTHENTICATED_USER() #AnonymousUser匿名用户
  11. else:
  12. self.user = None
  13.  
  14. if api_settings.UNAUTHENTICATED_TOKEN:
  15. self.auth = api_settings.UNAUTHENTICATED_TOKEN() #None
  16. else:
  17. self.auth = None

面向对象知识:

子类继承 父类,调用方法的时候:

  • 优先去自己里面找有没有这个方法,有就执行自己的
  • 只有当自己里面没有这个方法的时候才会去父类找

因为authenticate方法我们自己写,所以当执行authenticate()的时候就是执行我们自己写的认证

父类中的authenticate方法

  1. def authenticate(self, request):
  2. return (self.force_user, self.force_token)

我们自己写的

  1. class Authentication(APIView):
  2. '''用于用户登录验证'''
  3. def authenticate(self,request):
  4. token = request._request.GET.get('token')
  5. token_obj = models.UserToken.objects.filter(token=token).first()
  6. if not token_obj:
  7. raise exceptions.AuthenticationFailed('用户认证失败')
  8. #在rest framework内部会将这两个字段赋值给request,以供后续操作使用
  9. return (token_obj.user,token_obj)

认证的流程就是上面写的,弄懂了原理,再写代码就更容易理解为什么了。

4.3.配置文件

继续解读源码

默认是去全局配置文件中找,所以我们应该在settings.py中配置好路径

api_settings源码

  1. api_settings = APISettings(None, DEFAULTS, IMPORT_STRINGS)
  2.  
  3. def reload_api_settings(*args, **kwargs):
  4. setting = kwargs['setting']
  5. if setting == 'REST_FRAMEWORK':
  6. api_settings.reload()

setting中‘REST_FRAMEWORK’中找

全局配置方法:

API文件夹下面新建文件夹utils,再新建auth.py文件,里面写上认证的类

settings.py

  1. #设置全局认证
  2. REST_FRAMEWORK = {
  3. "DEFAULT_AUTHENTICATION_CLASSES":['API.utils.auth.Authentication',] #里面写你的认证的类的路径
  4. }

auth.py

  1. # API/utils/auth.py
  2.  
  3. from rest_framework import exceptions
  4. from API import models
  5.  
  6. class Authentication(object):
  7. '''用于用户登录验证'''
  8. def authenticate(self,request):
  9. token = request._request.GET.get('token')
  10. token_obj = models.UserToken.objects.filter(token=token).first()
  11. if not token_obj:
  12. raise exceptions.AuthenticationFailed('用户认证失败')
  13. #在rest framework内部会将这两个字段赋值给request,以供后续操作使用
  14. return (token_obj.user,token_obj)
  15.  
  16. def authenticate_header(self, request):
  17. pass

在settings里面设置的全局认证,所有业务都需要经过认证,如果想让某个不需要认证,只需要在其中添加下面的代码:

  1. authentication_classes = [] #里面为空,代表不需要认证
  1. from django.shortcuts import render,HttpResponse
  2. from django.http import JsonResponse
  3. from rest_framework.views import APIView
  4. from API import models
  5. from rest_framework.request import Request
  6. from rest_framework import exceptions
  7. from rest_framework.authentication import BasicAuthentication
  8.  
  9. ORDER_DICT = {
  10. 1:{
  11. 'name':'apple',
  12. 'price':15
  13. },
  14. 2:{
  15. 'name':'dog',
  16. 'price':100
  17. }
  18. }
  19.  
  20. def md5(user):
  21. import hashlib
  22. import time
  23. #当前时间,相当于生成一个随机的字符串
  24. ctime = str(time.time())
  25. m = hashlib.md5(bytes(user,encoding='utf-8'))
  26. m.update(bytes(ctime,encoding='utf-8'))
  27. return m.hexdigest()
  28.  
  29. class AuthView(APIView):
  30. '''用于用户登录验证'''
  31.  
  32. authentication_classes = [] #里面为空,代表不需要认证
  33.  
  34. def post(self,request,*args,**kwargs):
  35. ret = {'code':1000,'msg':None}
  36. try:
  37. user = request._request.POST.get('username')
  38. pwd = request._request.POST.get('password')
  39. obj = models.UserInfo.objects.filter(username=user,password=pwd).first()
  40. if not obj:
  41. ret['code'] = 1001
  42. ret['msg'] = '用户名或密码错误'
  43. #为用户创建token
  44. token = md5(user)
  45. #存在就更新,不存在就创建
  46. models.UserToken.objects.update_or_create(user=obj,defaults={'token':token})
  47. ret['token'] = token
  48. except Exception as e:
  49. ret['code'] = 1002
  50. ret['msg'] = '请求异常'
  51. return JsonResponse(ret)
  52.  
  53. class OrderView(APIView):
  54. '''订单相关业务'''
  55.  
  56. def get(self,request,*args,**kwargs):
  57. # self.dispatch
  58. #request.user
  59. #request.auth
  60. ret = {'code':1000,'msg':None,'data':None}
  61. try:
  62. ret['data'] = ORDER_DICT
  63. except Exception as e:
  64. pass
  65. return JsonResponse(ret)

API/view.py代码

再测试一下我们的代码

不带token发请求

带token发请求

五、drf的内置认证

rest_framework里面内置了一些认证,我们自己写的认证类都要继承内置认证类 "BaseAuthentication"

4.1.BaseAuthentication源码:

  1. class BaseAuthentication(object):
  2. """
  3. All authentication classes should extend BaseAuthentication.
  4. """
  5.  
  6. def authenticate(self, request):
  7. """
  8. Authenticate the request and return a two-tuple of (user, token).
  9. """
  10. #内置的认证类,authenticate方法,如果不自己写,默认则抛出异常
  11. raise NotImplementedError(".authenticate() must be overridden.")
  12.  
  13. def authenticate_header(self, request):
  14. """
  15. Return a string to be used as the value of the `WWW-Authenticate`
  16. header in a `401 Unauthenticated` response, or `None` if the
  17. authentication scheme should return `403 Permission Denied` responses.
  18. """
  19. #authenticate_header方法,作用是当认证失败的时候,返回的响应头
  20. pass

4.2.修改自己写的认证类

自己写的Authentication必须继承内置认证类BaseAuthentication

  1. # API/utils/auth/py
  2.  
  3. from rest_framework import exceptions
  4. from API import models
  5. from rest_framework.authentication import BaseAuthentication
  6.  
  7. class Authentication(BaseAuthentication):
  8. '''用于用户登录验证'''
  9. def authenticate(self,request):
  10. token = request._request.GET.get('token')
  11. token_obj = models.UserToken.objects.filter(token=token).first()
  12. if not token_obj:
  13. raise exceptions.AuthenticationFailed('用户认证失败')
  14. #在rest framework内部会将这两个字段赋值给request,以供后续操作使用
  15. return (token_obj.user,token_obj)
  16.  
  17. def authenticate_header(self, request):
  18. pass

4.3.其它内置认证类

rest_framework里面还内置了其它认证类,我们主要用到的就是BaseAuthentication,剩下的很少用到

六、总结

自己写认证类方法梳理

(1)创建认证类

  • 继承BaseAuthentication    --->>1.重写authenticate方法;2.authenticate_header方法直接写pass就可以(这个方法必须写)

(2)authenticate()返回值(三种)

  • None ----->>>当前认证不管,等下一个认证来执行
  • raise exceptions.AuthenticationFailed('用户认证失败')       # from rest_framework import exceptions
  • 有返回值元祖形式:(元素1,元素2)      #元素1复制给request.user;  元素2复制给request.auth

(3)局部使用

  • authentication_classes = [BaseAuthentication,]

(4)全局使用

  1. #设置全局认证
  2. REST_FRAMEWORK = {
  3. "DEFAULT_AUTHENTICATION_CLASSES":['API.utils.auth.Authentication',]
  4. }

源码流程

--->>dispatch

    --封装request

       ---获取定义的认证类(全局/局部),通过列表生成式创建对象 

     ---initial

       ----peform_authentication

         -----request.user   (每部循环创建的对象)

    

Django-rest-framework源码分析----认证的更多相关文章

  1. Django rest framework源码分析(1)----认证

    目录 Django rest framework(1)----认证 Django rest framework(2)----权限 Django rest framework(3)----节流 Djan ...

  2. Django rest framework 源码分析 (1)----认证

    一.基础 django 2.0官方文档 https://docs.djangoproject.com/en/2.0/ 安装 pip3 install djangorestframework 假如我们想 ...

  3. Django rest framework源码分析(一) 认证

    一.基础 最近正好有机会去写一些可视化的东西,就想着前后端分离,想使用django rest framework写一些,顺便复习一下django rest framework的知识,只是顺便哦,好吧. ...

  4. Django rest framework源码分析(3)----节流

    目录 Django rest framework(1)----认证 Django rest framework(2)----权限 Django rest framework(3)----节流 Djan ...

  5. Django rest framework源码分析(4)----版本

    版本 新建一个工程Myproject和一个app名为api (1)api/models.py from django.db import models class UserInfo(models.Mo ...

  6. Django rest framework源码分析(2)----权限

    目录 Django rest framework(1)----认证 Django rest framework(2)----权限 Django rest framework(3)----节流 Djan ...

  7. 3---Django rest framework源码分析(3)----节流

    Django rest framework源码分析(3)----节流 目录 添加节流 自定义节流的方法  限制60s内只能访问3次 (1)API文件夹下面新建throttle.py,代码如下: # u ...

  8. Django之REST framework源码分析

    前言: Django REST framework,是1个基于Django搭建 REST风格API的框架: 1.什么是API呢? API就是访问即可获取数据的url地址,下面是一个最简单的 Djang ...

  9. Django Rest Framework源码剖析(八)-----视图与路由

    一.简介 django rest framework 给我们带来了很多组件,除了认证.权限.序列化...其中一个重要组件就是视图,一般视图是和路由配合使用,这种方式给我们提供了更灵活的使用方法,对于使 ...

  10. Django Rest Framework源码剖析(三)-----频率控制

    一.简介 承接上篇文章Django Rest Framework源码剖析(二)-----权限,当服务的接口被频繁调用,导致资源紧张怎么办呢?当然或许有很多解决办法,比如:负载均衡.提高服务器配置.通过 ...

随机推荐

  1. zjoi网络

    map加LCT水一下就过了 # include <stdio.h> # include <stdlib.h> # include <iostream> # incl ...

  2. Hadoop 安装流程

    前言:因项目中需要数据分析,因而使用hadoop集群通过离线的方式分析数据 参考着网上的分享的文章实施整合的一篇文章,实施记录 安装流程: 1.设置各个机器建的ssh 无密码登陆 2.安装JDK 3. ...

  3. Kendo UI ASP.Net MVC 实现多图片及时显示加上传(其中有借鉴别人的代码,自己又精简了一下,如有冒犯,请多原谅!)

    View: <div class="demo-section k-content"> @(Html.Kendo().Upload() .Name("files ...

  4. vmstat结果在不同操作系统上的解释

    vmstat是各种unix上的通用工具,但在不同系统上,结果的解释却不同,最容易混淆的是结果的memory部分: 1.linux: vmstat输出结果中: memory: swapd:已用swap区 ...

  5. OV摄像头SCCB通信协议

    /*! * COPYRIGHT NOTICE * Copyright (c) 2013,山外科技 * All rights reserved. * 技术讨论:山外论坛 http://www.vcan1 ...

  6. 使用CMD命令编译和运行Java程序

    对于初学者来说,使用CMD命令(Unix以及类Unix系统采用Termial)来编译和运行Java的好处是让初学者直观地体会到编译(Compile)这一步骤,加深记忆.所谓编译就是将文本文件xxx.j ...

  7. Qt下载地址

    上Qt官网http://www.qt.io/download/想下载Qt,速度很慢,在这里记录下在Qt官网看到的镜像下载地址: 1. 所有Qt版本下载地址: http://download.qt.io ...

  8. js--DOM&BOM总结思维导图---2017-03-24

  9. poj 3620

    题意:给出一个矩阵,其中有些格子干燥.有些潮湿. 如果一个潮湿的格子的相邻的四个方向有格子也是潮湿的,那么它们就可以构成更大 的湖泊,求最大的湖泊. 也就是求出最大的连在一块儿的潮湿的格子的数目. # ...

  10. Oracle 12c(12.1.0.5)OEM server agent 安装配置

    注意: 此文档为生产上操作文档,省略了IP,oracle用户server,agent 端至少需要sudo,ping,ssh,创建目录权限. 一.安装要求 1.1. 系统情况一览 IP 数据库 OEM ...