django网页制作()FORM表单

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.

发布了306 篇原创文章 · 获赞 114 · 访问量 117万+

猜你喜欢

转载自blog.csdn.net/sjpljr/article/details/103099299
今日推荐