首页 > 其他分享 >基于Vue项目+django写一个登录的页面

基于Vue项目+django写一个登录的页面

时间:2023-02-21 21:33:30浏览次数:46  
标签:username Vue 登录 request django password data 页面

基于Vue项目+django写一个登录的页面

前端

借用了一下vue项目模板的AboutView.vue 页面组件
<template>
  <div class="about">
    <h1>登录功能</h1>

    <p>输入用户名<input type="text" v-model="username"></p>
    <p>输入密码<input type="text" v-model="password"></p>
    <button @click="handleClick">登录</button>
  </div>
</template>


<script>
import axios from 'axios'
export default {
  name:'AboutView',
  data(){
    return{username:'',password:''}
  },
  methods:{
    handleClick(){
      console.log(this.username,this.password)
      axios.post('http://127.0.0.1:8000/login/',{username:this.username,password:this.password})
          .then(res=>{alert(res.data.msg)})
    }
  },
  components:{

  }


}

</script>
django后端

路由层就不说了,记得/的匹配问题,前端写了/就一定要/
视图层
import json

from django.shortcuts import render
from django.http import JsonResponse




def loginfunc(request):
    if request.method == 'POST':
        request.data = json.loads(request.body)
        username = request.data.get('username')
        password = request.data.get('password')
        if username == 'jack' and password == '123':

            return JsonResponse({'msg': '登录成功'})
        else:

            return JsonResponse({'msg': '登录失败'})
    return JsonResponse({'msg': '登录失败'})



解决跨域

https://www.cnblogs.com/liuqingzheng/articles/17132395.html
    
第六点,复制着来就行

标签:username,Vue,登录,request,django,password,data,页面
From: https://www.cnblogs.com/wznn125ml/p/17142533.html

相关文章

  • props其他、混入mixin、插件、elementui使用(重点)、vuex、vue Router、localStorage
    目录1props其他2混入mixin3插件4elementui使用(重点)5vuex6vueRouter7localStorage系列1props其他#安装依赖 cnpminstall#做成纯净的vue项目 -在router......
  • Vue数据存储及vuex状态管理
    Vue数据存储及vuex状态管理我们想要往浏览器客户端存储数据,有三种方式:localStorage——存储到本地,浏览器重新开数据还存在sessionStorage——存储到浏览器应用,浏......
  • vue-cil02
    今日内容props其他#安装依赖 cnpminstall#做成纯净的vue项目 -在router的index.js中删除about的路由 -删除所有小组件和about页面组件 -App.vue上只保留......
  • 父传子 props其他使用方法,混入 mixin,插件,Vue操作cookie,vue Router 设置跳转路由,v
    目录父传子props其他使用方法混入mixin页面组件局部使用混入对象main全局使用插件使用方法1.新建包plugins2.页面组件Vue操作cookie的几种方式1.localStorage永久存储,除......
  • vue3 + ts
    安装#Vite需要Node.js版本>=12.0.0npminitvite@latest#根据相关问题进行回答#需要选择框架以及使用语言配置项目名#进入项目目录cdvite-project#......
  • Django学习笔记记录(整理了B站武老师的讲课课件,供大家学习)
    day1、初识DjangoPython知识点:函数、面向对象。前端开发:HTML、CSS、JavaScript、jQuery、BootStrap。MySQL数据库。Python的Web框架:Flask,自身短小精悍+第三方组......
  • Vue路由插件使用 -- vue-router
    Vue路由插件使用--vue-router路由插件可以在创建项目时就在手动配置时下载安装。如果没有创建时没有下载,那也可以用npm或cnpm安装。npminstallvue-router@4路由设......
  • Vue-cli混入、elementUI的使用、vue-router、Vuex
    目录混入、elementUI的使用、vue-router、Vuex一、Vue项目改成比较纯净的状态及props其他使用1.Vue项目改成纯净的项目2.props的其他使用二、混入(mixin)三、elementUI的使......
  • FreeMarker模板引擎的使用、实现静态化页面
    (目录)freemarker页面静态化技术1.1freemarker介绍FreeMarker是一款模板引擎:即一种基于模板和要改变的数据,并用来生成输出文本(HTML网页,电子邮件,配置文件,源代码......
  • vue3 vite异步组件路由懒加载
    引言在Vue2中,异步组件和路由懒加载处理使用import就可以很轻松实现。但是在Vue3.x中异步组件的使用与Vue2.x完全不同了。本文就详细讲讲vue3中异步组件和路由懒......