PS:浏览器页面请求的都是get请求

PS:post请求是通过form表单,ajax请求

request里面的常用方法

def index(request):
  print(request.META)   #请求对象的所有内容都包含在了这个META里面,包括访问的地址等等信息
    #request就是一个对象,请求对象,请求的所有东西都被封装到requres里
print(request.method) #请求方式分get和post,如果是get请求,则method打印出来的是get,同理post
print(request.path) #请求的地址
print(request.get_full_path()) #请求的全路径
print(request.GET) #请求get形式传的参数,全都在这里,以字典形式
print(request.body) #请求体的内容
print(request.POST) #以post请求的参数全在这里
return render(request,'index.html')

PS:当requests.POST的时候发送数据使用data封装的,取值的时候直接用post取值即可,如果发送数据时候是用json封装的,则取值的时候必须在body中取值 

request参数实例

urls.py  #这个是总路由

from django.conf.urls import url,include  #include就是用来做路由分发的
from django.contrib import admin from app01 import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'index/',views.index)
]

index.html   #模板层内

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>我是首页</title>
</head>
<body>
<h1>django的index页面</h1>
{# action:请求的地址 / post:请求的方式 #}
{# action里的地址可以写全路径,也可以只写一个地址名字index,不写也可以就默认当前路径 #}
<form action="http://127.0.0.1:8000/index/" method="post">
<p>
名字:<input type="text" name="name">
</p>
<p>
密码:<input type="password" name="pwd">
</p>
<input type="submit" value="提交">
</form>
</body>
</html>

views.py   #这个是app的视图层

from django.shortcuts import render,HttpResponse,redirect,reverse

def test(request):
return HttpResponse('我是app01的test') def index(request):
print(request.method)
print(request.path)
print(request.get_full_path())
print(request.GET)
print(request.body)
print(request.POST)
return render(request,'index.html')

点击提交出现

注释掉settings里面的

简单的登陆功能实例

views.py   #app下的视图层

from django.shortcuts import render,HttpResponse,redirect,reverse

def test(request):
return HttpResponse('我是app01的test') def login(request):
if request.method == 'GET':
return render(request,'login.html')
elif request.method == 'POST':
print(request.POST)
name = request.POST.get('name') #name = request.POST[name] 也可以这样取值,但是当无值的时候会报错
pwd = request.POST.get('pwd')
print(name)
print(pwd)
if name == 'lqz' and pwd == '123':
return redirect('http://www.baidu.com')
else:
return HttpResponse('用户名或密码错误')

login.html   #模板层的页面文件

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登陆页面</title>
</head>
<body>
<form action="http://127.0.0.1:8000/login/" method="post">
<p>
名字:<input type="text" name="name">
</p>
<p>
密码:<input type="password" name="pwd">
</p>
<input type="submit" value="提交">
</form>
</body>
</html>

urls.py

from django.conf.urls import url,include  #include就是用来做路由分发的
from django.contrib import admin from app01 import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'login/',views.login)
]

(8)视图层参数request详解的更多相关文章

  1. iOS 视图控制器转场详解

    iOS 视图控制器转场详解 前言的前言 唐巧前辈在微信公众号「iOSDevTips」以及其博客上推送了我的文章后,我的 Github 各项指标有了大幅度的增长,多谢唐巧前辈的推荐.有些人问我相关的问题 ...

  2. Scala 深入浅出实战经典 第62讲:Scala中上下文界定内幕中的隐式参数实战详解

    王家林亲授<DT大数据梦工厂>大数据实战视频 Scala 深入浅出实战经典(1-87讲)完整视频.PPT.代码下载: 百度云盘:http://pan.baidu.com/s/1c0noOt ...

  3. Scala 深入浅出实战经典 第60讲:Scala中隐式参数实战详解以及在Spark中的应用源码解析

    王家林亲授<DT大数据梦工厂>大数据实战视频 Scala 深入浅出实战经典(1-87讲)完整视频.PPT.代码下载:百度云盘:http://pan.baidu.com/s/1c0noOt6 ...

  4. Oracle GoldenGate中HANDLECOLLISIONS参数使用详解

    Oracle GoldenGate中HANDLECOLLISIONS参数使用详解   HANDLECOLLISIONS 是一个 replicat 进程参数,主要在 initial load 中使用.在 ...

  5. 机器学习——随机森林,RandomForestClassifier参数含义详解

    1.随机森林模型 clf = RandomForestClassifier(n_estimators=200, criterion='entropy', max_depth=4) rf_clf = c ...

  6. DAX/PowerBI系列 - 查询参数用法详解(Query Parameter)

    PowerBI  - 查询参数用法详解(Query Parameter) 很多人都不知道查询参数用来干啥,下面总结一下日常项目中常用的几个查询参数的地方.(本人不太欢hardcode的东西) 使用查询 ...

  7. MySQL高可用架构之Mycat-关于Mycat安装和参数设置详解

    MySQL高可用架构之Mycat-关于Mycat安装和参数设置详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Mycat介绍 1>.什么是Mycat Mycat背后是 ...

  8. java newInstance() 的参数版本与无参数版本详解

    newInstance() 的参数版本与无参数版本详解 博客分类: Core Java   通过反射创建新的类示例,有两种方式: Class.newInstance() Constructor.new ...

  9. [转帖]技术扫盲:新一代基于UDP的低延时网络传输层协议——QUIC详解

    技术扫盲:新一代基于UDP的低延时网络传输层协议——QUIC详解    http://www.52im.net/thread-1309-1-1.html   本文来自腾讯资深研发工程师罗成的技术分享, ...

随机推荐

  1. javascript 多个onclick function 取对应值

    方法1: 直接获取值 <button onclick="aa(1)">执行</button> <button onclick="aa(2)& ...

  2. ubuntu16.10 安装ibus中文输入法

    安装以下几种常用输入法: IBus拼音:sudo apt-get install ibus-pinyin IBUS五笔:sudo apt-get install ibus-table-wubi 谷歌拼 ...

  3. HDU 1005 Number Sequence(数论)

    HDU 1005 Number Sequence(数论) Problem Description: A number sequence is defined as follows:f(1) = 1, ...

  4. AI工具(矩形工具)(椭圆工具的操作与矩形类似)(剪切蒙版)5.11

    矩形工具:按住SHIFT键,可以绘制一个正方形. 按住ALT键,可以绘制以落点为中心的矩形. 同时按住SHIFT和ALT键可以绘制以鼠标落点为中心的正方形. 选择矩形工具,点击页面,输入高宽,精确绘制 ...

  5. AdaBoost, LogitBoost and GradientBoosting

    前向分步算法与加法模型(forward stagewise algorithm and additive model) (1) AdaBoost:前向分步算法中损失函数取指数损失函数 (2) Logi ...

  6. learning at command AT+CSQ

    AT command AT+CSQ [Purpose]        Learning how to get mobile module single quality report   [Eeviro ...

  7. Promise,async/await解决回调地狱

    先说一下async的用法,它作为一个关键字放到函数前面,用于表示函数是一个异步函数,因为async就是异步的意思, 异步函数也就意味着该函数的执行不会阻塞后面代码的执行. 写一个async 函数 as ...

  8. Java单例模式《二》懒汉式

    package com.study.mode; /** * 单例模式: 懒汉式,需要的时候创建. * @ClassName: SingleBean2 * @author BlueLake * @dat ...

  9. :命令模式:Command

    #ifndef __COMMAND_H__ #define __COMMAND_H__ #include <vector> #include "Equipment.h" ...

  10. 深入理解java虚拟机---虚拟机工具jinfo(十五)

    作用: 实时查看和调整虚拟机参数. jinfo 是jdk自带的一个工具,它可以用来查看正在运行的java应用程序的扩展参数(JVM中-X标示的参数):甚至支持在运行时修改部分参数. 1.通过以下的命令 ...