Django 表單
http://www.runoob.com/django/django-form.html
Django shortcut functions | Django documentation | Django https://docs.djangoproject.com/en/2.0/topics/http/shortcuts/
render_to_response()¶render_to_response(template_name, context=None, content_type=None, status=None, using=None)[source]¶Deprecated since version 2.0.
This function preceded the introduction of render() and works similarly except that it doesn’t make the request available in the response.
HTTP 請求HTTP協議以"請求-回覆"的方式工作。客戶發送請求時,可以在請求中附加數據。服務器通過解析請求,就可以獲得客戶傳來的數據,並根據URL來提供特定的服務。GET 方法我們在之前的項目中創建一個 search.py 文件,用於接收用戶的請求:
search.py代碼如下:
#_*_coding:utf-8_*_
from django.http import HttpResponse
from django.shortcuts import render_to_response
def search_form(request):
return render_to_response('search_form.html')
def search(request):
request.encoding='utf-8'
if 'q' in request.GET:
message='你內容爲:'+request.GET['q']
else:
message='ddsd'
return HttpResponse(message)
Request and response objects | Django documentation | Django https://docs.djangoproject.com/en/2.0/ref/request-response/
HttpRequest.GET¶
A dictionary-like object containing all given HTTP GET parameters. See the QueryDict documentation below.
HttpRequest.POST¶
A dictionary-like object containing all given HTTP POST parameters, providing that the request contains form data. See the QueryDict documentation below. If you need to access raw or non-form data posted in the request, access this through the HttpRequest.body attribute instead.
It’s possible that a request can come in via POST with an empty POST dictionary – if, say, a form is requested via the POST HTTP method but does not include form data. Therefore, you shouldn’t use if request.POST to check for use of the POST method; instead, use if request.method == "POST" (see HttpRequest.method).
POST does not include file-upload information. See FILES.