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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值