djangoWeb应用框架+MySQL数据5

  • 1. models.py文件设置相关变量类型
  • 2.迁移数据库
    • 2.1 创建app(Django必须依赖app才能创建表)
      • 创建app输入终端命令:
        • python manage.py startapp web(web为创建app的名字)
    • 2.2 settings.py中添加创建的app
      • 在settings.py文件中配置刚刚创建的app信息

    • 2.3 迁移
      • 执行命令,迁移数据库到Mysql
  • 3.相关代码讲解
    • 3.1 append( )函数使用详解
      • 基本用法:
        • append() 函数可以向列表末尾添加元素
        • 语法:
          • list.append( element )为任何类型元素
        • 用法:
          • 列表末尾添加任意类型元素

          • 输出:

        • 注意: append() 函数添加的元素在列表的末尾而不是任意位置
    • 3.2 前端页面代码:
      • hml文件:
      • <div class="container">
            <div class="title">
                <text>Welcome!</text>
            </div>
        
            <div class="touxiang">
                <image class="images" src="common/images/pic1.jpg"></image>
            </div>
        
            <div class="middle">
                <div class="input-block">
                    <input id="username" class="input" type="text" maxlength="10" placeholder="用户名" onchange="inputAccount"></input>
                </div>
            </div>
        
            <div class="down">
                <div class="input-block">
                    <input id="password" class="input" type="text" maxlength="10" placeholder="密码" onchange="inputPassword"></input>
                </div>
            </div>
        
            <div class="denglu-button">
                <button class="btn" onclick="onClick">立即登录</button>
            </div>
        
            <div>
                <text class="text1">忘记密码?</text>
                <text class="text1">|</text>
                <text class="text1">立即注册</text>
            </div>
        
            <div>
                <text>{{winfo}}</text>
            </div>
        </div>

        css文件代码:

      • .container {
            flex-direction: column;
            justify-content: center;
            align-items: center;
            width: 100%;
            height: 100%;
        }
        
        .title {
            font-size: 40px;
            color: #000000;
            opacity: 0.9;
        }
        
        @media screen and (device-type: tablet) and (orientation: landscape) {
            .title {
                font-size: 100px;
            }
        }
        
        @media screen and (device-type: wearable) {
            .title {
                font-size: 28px;
                color: #FFFFFF;
            }
        }
        
        @media screen and (device-type: tv) {
            .container {
                background-image: url("/common/images/Wallpaper.png");
                background-size: cover;
                background-repeat: no-repeat;
                background-position: center;
            }
        
            .title {
                font-size: 100px;
                color: #FFFFFF;
            }
        }
        
        @media screen and (device-type: phone) and (orientation: landscape) {
            .title {
                font-size: 60px;
            }
        }
        
        .input{
            width: 70%;
            height: 6%;
            font-size: 15px;
            margin-top: 10px;
            border-radius: 20px;
        }
        
        .btn{
            margin-top: 10px;
            height: 7%;
            width: 35%;
        }
        
        .text1{
            font-size: 20px;
            justify-content: center;
            margin-top: 10px;
            font-size: 20px;
        }
        
        .images{
            height: 30%;
            width: 90%;
            border-radius: 50px;
        }

        js文件代码:

      • import router from '@system.router';
        import fetch from '@system.fetch';
        import qs from 'querystring';
        
        export default {
            data:{
                winfo:"" //定义winfo用于存放后端反馈数据
            },
            inputAccount(e){
                this.username = e.value;
            },
            inputPassword(e){
                this.password = e.value;
            },
            onClick(){
                fetch.fetch({
        //            url:`http://127.0.0.1:8007/Person/login/`,
                    url:`http://127.0.0.1:8000/Person/login/`,  //路径
                    data: qs.stringify({'username':'123','password':'*******'}),//验证,向后端发送请求
                    responseType:"json",//请求的参数类型
                    method: "POST",
                    success:(resp)=>
                    {
                        this.winfo = resp.data;//令获取到的后端数据赋给winfo
                        console.log("返回的数据:"+this.winfo);//打印出数据
                    },
                    fail:(resp)=>
                    {
                        this.winfo = resp.data;//令获取到的后端数据赋给winfo
                        console.log("获取数据失败:"+this.winfo)//打印出数据
                    }
                });
            }
        }

        效果展示:

      • 后端部分代码:

注意:在前后端实现数据库内容交互中一定要注意内容的类型保持一致,否则在try语句中不好辨别代码bug在哪里进而无法获取数据库内容 !!!在此非常感谢高金奇学长以及潘子涵学姐的援助。

成功页面展示:

 

 

 

 

 

 

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值