Django-Request and Response objects

翻译自:https://docs.djangoproject.com/zh-hans/2.2/ref/request-response/

快速浏览

Django使用 请求对象和相应对象(request and response objects )在系统中传递状态。

当一个页面被请求时,Django创建一个HttpRequest object,该对象包含关于请求的元数据。然后Django加载适当的视图,将HttpRequest作为第一个参数传递给视图函数。每个视图都负责返回HttpResponse object。例如,

# polls/views.py
def
detail(request, question_id): question = get_object_or_404(Question, pk=question_id) return render(request, 'polls/detail.html', {'question': question})
原文地址:https://www.cnblogs.com/daemonFlY/p/11504132.html