外贸wordpress建站,网站开发中常用的技术和工具,做网站用win2008系统,建设一个网站需要多少费用请求对象: HttpRequest 对象
get()#xff1a;返回字符串#xff0c;如果该键对应有多个值#xff0c;取出该键的最后一个值。
GET#xff1a;有相同的键#xff0c;就把所有的值放到对应的列表里
取值格式#xff1a;对象.方法。
def runoob(request): name re…请求对象: HttpRequest 对象
get()返回字符串如果该键对应有多个值取出该键的最后一个值。
GET有相同的键就把所有的值放到对应的列表里
取值格式对象.方法。
def runoob(request): name request.GET.get(name) return HttpResponse(姓名{}.format(name))
POST常用于 form 表单form 表单里的标签 name 属性对应参数的键value 属性对应参数的值
def runoob(request): name request.POST.get(name) return HttpResponse(姓名{}.format(name))
BODY数据类型是二进制字节流是原生请求体里的参数内容
def runoob(request): name request.body print(name) return HttpResponse(hello)
path获取 URL 中的路径部分数据类型是字符串
def runoob(request): name request.path print(name) return HttpResponse(world)
method获取当前请求的方式数据类型是字符串且结果为大写
def runoob(request): name request.method print(name) return HttpResponse(hello world)
响应对象HttpResponse 对象
响应对象主要有三种形式HttpResponse()、render()、redirect()。
HttpResponse(): 返回文本参数为字符串字符串中写文本内容
def runoob(request): # return HttpResponse(你好) return HttpResponse(a hrefhttps://www.runoob.com/你好/a)
render(): 返回文本第一个参数为 request第二个参数为字符串页面名称第三个参数为字典可选参数向页面传递的参数键为页面参数名值为views参数名。
def runoob(request): name 张三 return render(request,runoob.html,{name:name})
redirect()重定向跳转新页面。参数为字符串字符串中填写页面路径。一般用于 form 表单提交后跳转到新页面。
def runoob(request): return redirect(/index/)
render 和 redirect 是在 HttpResponse 的基础上进行了封装 render底层返回的也是 HttpResponse 对象 redirect底层继承的是 HttpResponse 对象