国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Vue_Django 登錄注冊+圖書管理系統(tǒng)

這篇具有很好參考價值的文章主要介紹了Vue_Django 登錄注冊+圖書管理系統(tǒng)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

Vue前端

注冊頁面

點擊查看代碼
<template>
  <div class="register">
    <el-row :gutter="20">
      <el-col :span="12" :offset="6">
        <div class="grid-content bg-purple">
          <h1>注冊頁面</h1>
          <el-form  status-icon  ref="ruleForm" label-width="100px"
                   class="demo-ruleForm">
            <el-form-item label="用戶名" prop="username">
              <el-input v-model.number="username"></el-input>
            </el-form-item>
            <el-form-item label="密碼" prop="pass">
              <el-input type="password" v-model="pass" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="確認(rèn)密碼" prop="checkPass">
              <el-input type="password" v-model="checkPass" autocomplete="off"></el-input>
            </el-form-item>

            <el-form-item>
              <el-button type="primary" @click="submitForm">提交</el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import axios from "axios";

export default {
  data() {
    return {
      username:'',
      pass:'',
      checkPass:'',
    };
  },
  methods: {
    submitForm() {
      axios.post('http://127.0.0.1:8000/register/', {
        username: this.username,
        pass:this.pass,
        checkPass:this.checkPass
      })
          .then(function (res) {
            if (res.data.code===100){
              location.href = 'http://localhost:8080/login'
            }else {
              alert(res.data.msg)
            }
          })
    },
  }
}
</script>

登錄

點擊查看代碼
<template>
  <div class="login">
    <el-row :gutter="20">
      <el-col :span="12" :offset="6">
        <div class="grid-content bg-purple">
          <h1>登錄頁面</h1>
          <el-form status-icon ref="ruleForm" label-width="100px"
                   class="demo-ruleForm">
            <el-form-item label="用戶名" prop="username">
              <el-input v-model.number="username"></el-input>
            </el-form-item>
            <el-form-item label="密碼" prop="pass">
              <el-input type="password" v-model="pass" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="submitForm">提交</el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import axios from "axios";

export default {
  data() {
    return {
      username:'',
      pass:'',
    };
  },
  methods: {
    submitForm() {
      axios.post('http://127.0.0.1:8000/login/', {
        username: this.username,
        pass:this.pass,
      })
          .then(function (res) {
            if (res.data.code===100){
              location.href = 'http://localhost:8080/'
            }else {
              alert(res.data.msg)
            }
          })
    },
  }
}
</script>

查看所有圖書

點擊查看代碼
<template>
  <div class="name">
    <h1>圖書管理</h1>
    <el-row :gutter="20">
      <el-col :span="12" :offset="6">
        <div class="grid-content bg-purple">
          <el-button type="success" @click="handleCreate">增加圖書</el-button>
          <el-table
              :data="tableData"
              style="width: 100%">
            <el-table-column
                prop="id"
                label="圖書id"
                width="180">
            </el-table-column>
            <el-table-column
                prop="name"
                label="圖書名稱"
                width="180">
            </el-table-column>
            <el-table-column
                prop="price"
                label="價格">
            </el-table-column>
            <el-table-column
                prop="operate"
                label="操作">
              <template slot-scope="scope">
                <el-button
                    size="mini"
                    type="primary"
                    @click="handleEdit(scope.$index, scope.row)">修改
                </el-button>
                <el-button
                    size="mini"
                    type="danger"
                    @click="handleDelete(scope.$index, scope.row)">刪除
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import axios from "axios";

export default {
  name: 'HomeView',
  data() {
    return {
      // tableData: [{
      //   id:'',
      //   name:'',
      //   price:''
      // }],
      tableData:[]
    }
  },
  created() {
    axios.get('http://127.0.0.1:8000/book').then(res => {
      this.tableData = res.data
      // console.log(res.data)
      // res.data.forEach((value, index) => {
      //   this.tableData.id = index
      //   this.tableData.name = value.name
      //   this.tableData.price = value.price
      //   console.log(this.tableData)
      // })
    })
  },
  methods: {
    handleCreate() {
      this.$router.push('/create')
    },
    handleEdit(index, row) {
      // console.log(index, row);
      // console.log(row.name)
      // console.log(row.price)
      this.$router.push({name: 'update', params: {id: row.id, bookName: row.name, bookPrice: row.price}})
    },
    handleDelete(index, row) {
      console.log(index, row);
      console.log(row.id)
      axios.delete('http://127.0.0.1:8000/book/' + row.id).then(res => {
        this.$message({
          message: '刪除成功',
          type: 'success',
          duration: 1000, // 設(shè)置為 1 秒鐘
          onClose: () => {
            setTimeout(() => {
              location.reload()
            })
          }
        });
      })
    }
  }
}
</script>

新增圖書

點擊查看代碼
<template>
  <div class="create">
    <el-row :gutter="20">
      <el-col :span="12" :offset="6">
        <div class="grid-content bg-purple" style="margin-top: 40px">
          <h1>添加圖書</h1>
          <el-row :gutter="20">
            <el-col :span="14" :offset="5">
              <el-input v-model="name" placeholder="圖書名字"></el-input>
              <el-input v-model="price" placeholder="圖書價格" style="margin-top: 20px"></el-input>
              <el-button type="success" @click="handleSend" style="float: right;margin-top: 20px">確認(rèn)添加</el-button>
            </el-col>
          </el-row>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import axios from "axios";

export default {
  name: "BookCreateView",
  data() {
    return {
      name: '',
      price: ''
    }
  },
  methods: {
    handleSend() {
      axios.post('http://127.0.0.1:8000/book/', {
        name: this.name,
        price: this.price,
      }).then(res => {
        this.$message({
          message: '添加成功',
          type: 'success',
          duration: 1000, // 設(shè)置為 1 秒鐘
          onClose: () => {
            setTimeout(() => {
              this.$router.push('/')
            })
          }
        });
      }).catch(error => {
        console.log(error); // 輸出錯誤信息
      });
    }
  }
}
</script>

修改圖書

點擊查看代碼
<template>
  <div class="update">
    <el-row :gutter="20">
      <el-col :span="12" :offset="6">
        <div class="grid-content bg-purple" style="margin-top: 40px">
          <h1>修改圖書</h1>
          <el-row :gutter="20">
            <el-col :span="14" :offset="5">
              <el-input v-model="name" :placeholder="bookName"></el-input>
              <el-input v-model="price" :placeholder="bookPrice" style="margin-top: 20px"></el-input>
              <el-button type="success" @click="handleSend(bookId)" style="float: right;margin-top: 20px">確認(rèn)修改
              </el-button>
            </el-col>
          </el-row>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import axios from "axios";

export default {
  name: "BookUpdateView",
  data() {
    return {
      name: '',
      price: '',
      bookId: '',
      bookName: '',
      bookPrice: ''
    }
  },
  created() {
    // console.log(this.$route.params.id)
    // console.log(this.$route.params.bookName)
    // console.log(this.$route.params.bookPrice)
    this.bookId = this.$route.params.id
    this.bookName = this.$route.params.bookName
    this.bookPrice = this.$route.params.bookPrice
  },
  methods: {
    handleSend(bookId) {
      axios.put('http://127.0.0.1:8000/book/' + bookId + '/', {
        name: this.name,
        price: this.price,
      }).then(response => {
        console.log(response.data); // 輸出成功修改的圖書信息
        this.$message({
          message: '修改成功',
          type: 'success',
          duration: 1000, // 設(shè)置為 1 秒鐘
          onClose: () => {
            setTimeout(() => {
              this.$router.push('/')
            })
          }
        });
      }).catch(error => {
        console.log(error); // 輸出錯誤信息
        alert('不能為空')
      });
    }
  }
}
</script>

Django后端

注冊

from rest_framework.views import APIView
from django.contrib import auth
from django.contrib.auth.models import User

class RegisterView(APIView):
    def post(self, request):
        back_dic = {'code': 100, 'msg': '注冊成功'}
        res = json.loads(request.body)
        username = res.get('username')
        password = res.get('pass')
        repassword = res.get('checkPass')
        user_obj = User.objects.filter(username=username)
        if user_obj:
            back_dic['code'] = 101
            back_dic['msg'] = '用戶名已存在'
            return Response(back_dic)
        if password != repassword:
            back_dic['code'] = 101
            back_dic['msg'] = '兩次密碼不一致'
            return Response(back_dic)
        if not username:
            back_dic['code'] = 101
            back_dic['msg'] = '用戶名不能為空'
            return Response(back_dic)

        User.objects.create_user(username=username, password=password)
        return Response(back_dic)

登錄

from rest_framework.views import APIView
from django.contrib import auth
from django.contrib.auth.models import User

class LoginView(APIView):
    def post(self, request):
        back_dic = {'code': 100, 'msg': '注冊成功'}
        res = json.loads(request.body)
        username = res.get('username')
        password = res.get('pass')
        user_obj = auth.authenticate(request, username=username, password=password)
        if user_obj:
            return Response(back_dic)
        else:
            back_dic['code'] = 101
            back_dic['msg'] = '用戶名或密碼錯誤'
            return Response(back_dic)

圖書接口(增刪改查)

from rest_framework.viewsets import ModelViewSet
from .models import Books
from .serializer import BookSerializer

class BookDetailView(ModelViewSet):
    queryset = Books.objects.all()
    serializer_class = BookSerializer

文章來源地址http://www.zghlxwxcb.cn/news/detail-479007.html

到了這里,關(guān)于Vue_Django 登錄注冊+圖書管理系統(tǒng)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • Django搭建圖書管理系統(tǒng)01

    Django搭建圖書管理系統(tǒng)01

    Django是一個使用Python編寫的開源Web應(yīng)用程序框架。它采用了MVC(Model-View-Controller)的軟件設(shè)計模式,旨在簡化開發(fā)復(fù)雜的Web應(yīng)用程序。 以下是Django框架的一些主要 特點 : 強大的開發(fā)工具:Django提供了一套完整的工具集,包括ORM(對象關(guān)系映射)、表單處理、URL路由、模板引

    2024年02月12日
    瀏覽(22)
  • Django項目之圖書管理系統(tǒng)

    1、創(chuàng)建好 Django 項目 2、準(zhǔn)備好數(shù)據(jù)庫 —— 創(chuàng)建數(shù)據(jù)庫:book_system 3、配置項目中的數(shù)據(jù)庫引擎 4、配置靜態(tài)文件的搜索路徑 , 以及在項目的根目錄中創(chuàng)建一個 static 存放靜態(tài)文件數(shù)據(jù)文件夾 5、導(dǎo)入 html 模板文件和靜態(tài)文件數(shù)據(jù)。 1、響應(yīng)用戶注冊頁面的視圖 2、定義用戶數(shù)

    2024年04月29日
    瀏覽(23)
  • 圖書管理系統(tǒng)(python、django)

    圖書管理系統(tǒng)(python、django)

    1. 系統(tǒng)簡介 該實驗設(shè)計開發(fā)一個簡單的圖書管理數(shù)據(jù)庫系統(tǒng),包括圖書館內(nèi)書籍的信息、學(xué)校在校師生的信息以及師生的借閱信息。此系統(tǒng)用戶面向圖書管理員和借閱讀者,圖書館管理員可以完成圖書、讀者等基本信息的增加、刪除和修改、查看;讀者可以進(jìn)行圖書的借閱、

    2024年02月05日
    瀏覽(33)
  • Django圖書商城系統(tǒng)實戰(zhàn)開發(fā)-實現(xiàn)商品管理

    在本教程中,我們將使用Django框架來實現(xiàn)一個簡單的圖書商城系統(tǒng),并重點討論如何實現(xiàn)商品管理功能。此外,我們還將介紹如何使用Markdown格式來寫博客,并將其集成到我們的圖書商城系統(tǒng)中。 Django是一個強大的Python Web框架,被廣泛應(yīng)用于開發(fā)各種類型的Web應(yīng)用程序,包括

    2024年02月12日
    瀏覽(18)
  • Django圖書商城系統(tǒng)實戰(zhàn)開發(fā)-實現(xiàn)訂單管理

    在本教程中,我們將繼續(xù)基于Django框架開發(fā)圖書商城系統(tǒng),這次的重點是實現(xiàn)訂單管理功能。訂單管理是一個電子商務(wù)系統(tǒng)中非常重要的部分,它涉及到用戶下單、支付、發(fā)貨以及訂單狀態(tài)的管理等方面。通過學(xué)習(xí)本教程,您將了解如何使用Django框架來構(gòu)建強大的訂單管理系

    2024年02月12日
    瀏覽(25)
  • 基于Django圖書管理系統(tǒng) 畢業(yè)設(shè)計源碼64946

    基于Django圖書管理系統(tǒng) 畢業(yè)設(shè)計源碼64946

    贈送源碼-畢業(yè)設(shè)計:django圖書管理系統(tǒng) https://www.bilibili.com/video/BV1Dw411J7Uf/?vd_source=72970c26ba7734ebd1a34aa537ef5301 Django圖書管理系統(tǒng) 摘 ?要 大數(shù)據(jù)時代下,數(shù)據(jù)呈爆炸式地增長。為了迎合信息化時代的潮流和信息化安全的要求,利用互聯(lián)網(wǎng)服務(wù)于其他行業(yè),促進(jìn)生產(chǎn),已經(jīng)是成為

    2024年01月23日
    瀏覽(23)
  • Django搭建圖書管理系統(tǒng)04:View視圖初探

    Django搭建圖書管理系統(tǒng)04:View視圖初探

    數(shù)據(jù)庫雖然已經(jīng)有了,但是用戶通常只需要這個龐大數(shù)據(jù)庫中的很小一部分進(jìn)行查看、修改等操作。為此還需要代碼來恰當(dāng)?shù)娜〕霾⒄故緮?shù)據(jù),這一部分代碼就被稱為 視圖 。 Django 中視圖的概念是**「一類具有相同功能和模板的網(wǎng)頁的集合」**。 首先寫一個最簡單的 視圖函數(shù)

    2024年02月15日
    瀏覽(16)
  • 項目篇 | 圖書管理系統(tǒng) | 賬號模塊 | 登錄

    該系統(tǒng)實現(xiàn)了管理員登錄和用戶登錄,二者的實現(xiàn)和邏輯幾乎完全一致,這里以用戶登錄為例進(jìn)行講解。 userLoginPage:功能頁,用戶登錄頁,實現(xiàn)用戶登錄頁的界面 userLogin:功能,用戶登錄,實現(xiàn)用戶登錄邏輯

    2024年01月20日
    瀏覽(21)
  • Django搭建圖書管理系統(tǒng)03:編寫博客文章的Model模型

    Django搭建圖書管理系統(tǒng)03:編寫博客文章的Model模型

    Django 框架主要關(guān)注的是模型(Model)、模板(Template)和視圖(Views),稱為MTV模式。 它們各自的職責(zé)如下: 層次 職責(zé) 模型(Model),即數(shù)據(jù)存取層 處理與數(shù)據(jù)相關(guān)的所有事務(wù): 如何存取、如何驗證有效性、包含哪些行為以及數(shù)據(jù)之間的關(guān)系等。 模板(Template),即業(yè)務(wù)邏

    2024年02月12日
    瀏覽(29)
  • 圖書推薦管理系統(tǒng)Python,基于Django和協(xié)同過濾算法等實現(xiàn)

    圖書推薦管理系統(tǒng)Python,基于Django和協(xié)同過濾算法等實現(xiàn)

    圖書推薦系統(tǒng) / 圖書管理系統(tǒng),以Python作為開發(fā)語言,基于Django實現(xiàn),使用協(xié)同過濾算法實現(xiàn)對登錄用戶的圖書推薦。 視頻+代碼:https://www.yuque.com/ziwu/yygu3z/gq555ph49m9fvrze Django是一個強大而靈活的Python Web框架,它為開發(fā)人員提供了一種高效構(gòu)建Web應(yīng)用程序的方式。Django的設(shè)計

    2024年02月12日
    瀏覽(92)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包