- <div class="cb-container"">
- <div class="cb-title">
- <text class="cb-title-text">
- 患者数据
- text>
- div>
- <div >
- <text style="">
- 姓名 :
- text>
- <text style="">{{detail[0].name}}text>
- div>
- <div>
- <text style="">
- 年龄 :
- text>
- <text style="">{{detail[0].age}}text>
- div>
- <div>
- <text style="">
- 身高 :
- text>
- <text style="">{{detail[0].high}}text>
- div>
- <div>
- <text style="">
- 体重 :
- text>
- <text style="">{{detail[0].weight}}text>
- div>
- <div>
- <text style="">
- 患病部位 :
- text>
- <text style="">{{detail[0].DiseasedSite}}text>
- div>
- <div class="container">
- <button onclick="onClick" class="btn-map" style="background-color: darkturquoise; height: 50px;width: 100px;">刷新button>
- div>
- <div class="container3">
- <text style="font-size: 70px;">
- {{winfo}}
- text>
- div>
- div>
必须加上的一条,否则默认在一行,会导致显示不清楚
- .cb-container{
- flex-direction: column;
- width: 100%;
- height: 100%;
- }
- import router from '@system.router';
- import fetch from '@system.fetch';
- import qs from 'querystring';
-
- export default {
- data:{
- winfo:"" ,//定义winfo用于存放后端反馈数据
- detail:[{ //初始化
- name:"张三",
- age:55,
- high:180,
- weight:64,
- DiseasedSite:"手臂"
- },
- {
- name:"李四"
- }
- ]
- },
- onClick(){
- fetch.fetch({
- url:`http://127.0.0.1:8000/shuju1/`, //后端路径,一定不能错,用的是反单引号
- data: qs.stringify({'patientname':'李四'}),//验证,将字符串转发给后端,后端会受到这个请求
- responseType:"json",//请求的参数类型
- method: "POST",
- success:(resp)=>
- {
- var getdata
- //将JSON字符串转换为JSON对象
- getdata = JSON.parse(resp.data)
- this.detail[0].name=getdata[0].name
- this.detail[0].age=getdata[0].age
- this.detail[0].high=getdata[0].height
- this.detail[0].weight=getdata[0].weight
- this.detail[0].DiseasedSite=getdata[0].DiseasedSite
- this.winfo = resp.data;//令获取到的后端数据赋给winfo
- console.log("返回的数据:"+this.winfo);//打印出数据
- console.log("a"+typeof(getdata));
- },
- fail:(resp)=>
- {
- console.log("获取数据失败:"+this.detail)//打印出数据
- }
- });
- }
- }

- from django.urls import path
- from apptest import views
- from apptest.views import denglu,shuju1
- # from . import views
-
- urlpatterns = [
- # path('admin/', admin.site.urls),
- path('index/', views.index),
- path('user/list', views.user_list),
- path('user/add', views.user_add),
- path('orm/', views.orm),
- # 请求和响应
- path('something/', views.something),
- # 登录页面
- path('denglu/', denglu.as_view()),
- path('shuju1/', shuju1.as_view()),//这行为本次重点
-
- ]
- from django.db import models
-
- class shuju(models.Model): # 建表,定义一个类Students,包含Name,Email,Age信息
- # userName = models.CharField(max_length=64, default="")
- Name = models.CharField(max_length=64, default="")
- Age = models.CharField(max_length=64, default="")
- Height = models.CharField(max_length=64, default="")
- Weight = models.CharField(max_length=64, default="")
- DiseasedSite = models.CharField(max_length=64, default="")
views.py
- from django.shortcuts import render, HttpResponse, redirect
- import pymysql
- from rest_framework.utils import json
- from rest_framework.views import APIView
- # Create your views here.
- from apptest import models
-
- try:
- con = pymysql.connect(host='127.0.0.1', # 或者是写localhost
- port=3306, # 端口号
- user='root', # MySQL登录用户名
- password='*****', # MySQL登录密码
- db='django', # 要连接的数据库名称
- charset='utf8') # 表的字符集
- print("数据库连接成功")
-
- except pymysql.Error as er:
- print('连接失败' + str(er)) # 打印异常
-
-
- class shuju1(APIView): # shuju类视图
- def post(self, request): # 创建post方法
- try:
- patientname = request.data.get('patientname') # 获取前端发送的patientname
- print(patientname) # 打印patientname
- result = models.shuju.objects.filter(Name=patientname).last()
- print(result)
- # 使用filter方法查询数据表中Name=patientname的数据,last方法为查询最新,加last后为字典
- name = result.Name # 获取result中的name
- age = result.Age # 获取result中的age
- weight = result.Weight # 获取result中的weight
- height = result.Height # 获取result中的height
- diseasedSite = result.DiseasedSite # 获取result中的diseasedSite
- alldata = [] # 创建空列表
- alldata.append({ # 写入如下字典,“键”要和前端对应
- 'name': name, 'age': age, 'weight': weight, 'height': height,
- 'DiseasedSite': diseasedSite,
- })
- alldata_json = json.dumps(alldata, ensure_ascii=False) # 使中文正确显示
- return HttpResponse(alldata_json)
- except shuju.DoesNotExist as e:
- print('刷新失败')
- else:
- return HttpResponse("请求失败")





