request对象方法 pycharm链接数据库(MYSQL)

 

 

request.method # 获取当前请求方式 全大写的字符串  POST或者GET

request.method # 返回请求方式 并且是全大写的字符串形式 <class 'str'>
request.POST # 获取用户post请求提交的普通数据不包含文件
request.POST.get() # 只获取列表最后一个元素
request.POST.getlist() # 直接将列表取出
request.GET # 获取用户提交的get请求数据
request.GET.get() # 只获取列表最后一个元素
request.GET.getlist() # 直接将列表取出

request.FILES#取文件、图片
request.body # 原生的浏览器发过来的二进制数据 后面详细的讲
request.path #取路径
request.path_info
request.get_full_path() 能过获取完整的url及问号后面的参数
"""
print(request.path) # /app01/ab_file/
print(request.path_info) # /app01/ab_file/
print(request.get_full_path()) # /app01/ab_file/?username=jason


"""
get请求携带的数据是有大小限制的 大概好像只有4KB左右
而post请求则没有限制
"""

 

 

 

html:多选时


  {% load static %}
<link rel="stylesheet" href="{% static 'bootstrap-3.3.7-dist/css/bootstrap.min.css' %}">
<scrip src="{% static 'bootstrap-3.3.7-dist/js/bootstrap.min.js' %}"></scrip>
</head>
<body>
<h1 class="text-center">登录</h1># 类似居中两侧留白
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<form action="" method="post">  # 这里一定要写post不然密码全看见了
<p>username:<input type="text" name="username" class="form-control"></p>
<p>password:<input type="password" name="password" class="form-control"></p>

<p>
<input type="checkbox" name="hobby" value="111">111
<input type="checkbox" name="hobby" value="222">222
<input type="checkbox" name="hobby" value="333">333
</p>
<input type="submit" class="btn btn-success btn-block">
</form>
</div>
</div>
</div>
</body>
 

views:

def login(request):
    #返回登录界面
    # print('来了 老弟')
    if request.method=='POST':
        username=request.POST.getlist('username')
        hobby=request.POST.getlist('hobby')
        print(hobby,type(hobby))
    # print(request.POST)
        return HttpResponse('收到了宝贝')
    return render(request,'login.html')

 

 

先创建好一个库,查找database

三个位置查找数据库相关
①右侧上方database
②左下方database
③配置里面的plugins插件搜索安装:

 

 

 

 

 

 

 

 

 

 

 

出现这个√就是可以连接,点击apply

 

 

 

posted @ 2023-11-20 20:36  朱饱饱  阅读(14)  评论(0)    收藏  举报