首页 > 其他分享 >VUE+Django前后端分离-第三部分【前后端数据传递】

VUE+Django前后端分离-第三部分【前后端数据传递】

时间:2022-08-15 19:23:38浏览次数:61  
标签:VUE http requestpara 前后 planid Django exceptionid data response

一、前端代码

首先:前端中任何变量都要被定义,具体如下:

 

 

 

<template>
    <div>
        <h3>推置引擎测试界面</h3>
        <el-form :inline="true" :model="formInline" class="demo-form-inline">
            <el-form-item label="异常id">
                <el-input v-model="formInline.exceptionid" placeholder="异常id"></el-input>
            </el-form-item>
            <el-form-item label="方案id">
                <el-input v-model="formInline.planid" placeholder="方案id"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">查询</el-button>
            </el-form-item>
        </el-form>

        <el-table :data="tableData" style="width: 90%">
            <el-table-column prop="formInline.rule" label="规则" width="1000">
            </el-table-column>
            <el-table-column prop="formInline.result" label="结果" width="180">
            </el-table-column>
        </el-table>
    </div>

</template>

<script>
    export default {
        data() {
            return {
                formInline: {
                    exceptionid: '',
                    planid: '',
                    rule: '',
                    result: '',
                },
                requestpara: {
                    exceptionid: '',
                    planid: '',
                }
            }
        },
        methods: {
            onSubmit() {
                this.requestpara.exceptionid = this.formInline.exceptionid
                this.requestpara.planid = this.formInline.planid
                this.$http.post('http://127.0.0.1:8000/calculate_testengine/',this.requestpara);
            }
        }
    }
</script>

<style>

</style>

二、后端代码

from django.http import JsonResponse
from django.views.decorators.http import require_http_methods

@require_http_methods(["POST"])
def testengine(request):
    print("这是个测试")
    print(request.POST)
    print(request.body)
    data = request.body.decode("utf-8")
    print("data",data)
    json_data =json.loads(data)
    exceptionid = json_data["exceptionid"]
    planid = json_data["planid"]
    response = {}
    try:
        response['msg'] = 'success'
        response['data'] = 'exceptionid 为{},plan_id为{}'.format(exceptionid,planid)
    except:
        response['msg'] = 'fail'
        response['data'] = 'exceptionid 不为{},plan_id不为{}'.format(exceptionid,planid)
    return JsonResponse(response)

三、展示效果

 

 

Request URL: http://127.0.0.1:8000/calculate_testengine/ Request Method:POST

Request Payload: {"exceptionid":"334668","planid":"AR220811000002"}

响应:

{     "msg": "success",     "data": "exceptionid 为334668,plan_id为AR220811000002" }

标签:VUE,http,requestpara,前后,planid,Django,exceptionid,data,response
From: https://www.cnblogs.com/like1824/p/16589383.html

相关文章

  • django ORM定义实现链表结构
    需求场景各种链表使用场景,如单串,双端链表等需求描述实现阶段间串联的可前进后退的关系模型逻辑分析节点间串联.主要需要控制的是前节点和后节点的顺序关系以及......
  • Pytest框架 — 07、Pytest的Fixture(部分前后置)(二)
    目录4、Fixture的相互调用5、Fixture复用6、Fixture缓存返回结果7、Fixture的后置处理(一)使用yield关键字实现后置(二)使用addfinalizer关键字实现后置(三)yield和addfinalizer......
  • django路由层
    1、django请求生命周期流程图2、路由层2.1路由匹配"""url方法第一个参数是正则表达式,只要第一个参数正则表达式能够匹配到内容那么就会立刻停止往下匹配.直接执行对......
  • 初识django与ORM
    一、django简介Python三大主流web框架django、flask、tornadodjango特点:大而全自带的功能特别特别特别的多类似于航空母舰不足之处:有时候过于笨重flask特点:小......
  • Vue+Leaflet.PM插件实现创建和编辑几何图形(点、线、面、圆等)
    场景Vue+Leaflet实现加载OSM显示地图:https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/122317394在上面加载显示OSM的基础上,使用Leaflet.pm插件实现在页面上......
  • Vue面试题-组件间通信方式
    父子组件:props(父传子)$emit/$on(子传父) $on已被Vue3废弃$parent/$children$children已被Vue3废弃ref隔代组件:透传:$attrs/$listeners$listners已被Vue3废......
  • 解决Vue报错Uncaught (in promise) NavigationDuplicated: Avoided redundant navigat
         有效的解决方法如下:(亲测有效)方法一:在router文件夹下,添加如下代码:Vue.use(Router)constrouter=newRouter({routes})constVueRouterPush......
  • 14 Django_forms组件之ChoiceField类型
    如果想要灵活应用ChoiceField,那么请看如下:classTransactionRecord(ActiveBaseModel):"""交易记录"""charge_type_class_mapping={1:"success",......
  • web和vue-cli
    1、什么是WebpackWebPack可以看做是模块打包机:它做的事情是,分析你的项目结构,找到JavaScript模块以及其它的一些浏览器不能直接运行的拓展语言(Scss,TypeScript等),并将其打包......
  • python 中实现切除fastq文件序列的前后若干碱基
     001、root@PC1:/home/test#lsa.fastqtest.pyroot@PC1:/home/test#cattest.py##测试程序#!/usr/bin/pythonin_file=open("a.fastq","r"......