Django的封装性很强,有时感觉”只见树木,不见森林”。
要理解Django框架,最重要的一点就是理解request和response对象。
Django 使用request 和response 对象在框架中传递状态。
所有的请求信息封装在request中,例如http or https, GET or POST,header等等, 而返回给客户端的信息封装在response中。
引用官方文档:
When a page is requested, Django creates an HttpRequest object that contains metadata about the request. Then Django loads the appropriate view, passing the HttpRequest as the first argument to the view function. Each view is responsible for returning an HttpResponse object.
有关HttpRequest和HttpResponse的详细信息可参考官方文档:
https://docs.djangoproject.com/en/1.11/ref/request-response/#django.http.HttpRequest