首页 > 解决方案 > django中的并发请求

问题描述

从 vue 对 Django API 的并发请求会返回对两者的最后一个请求的响应。

这是我的 vue 组件片段

methods:{
    users(){
          axios.get('users').then((response) => {
               this.sers = response.data;
             }).catch((error) => {
               console.log(error);
             });
    },
    new_users(){
        axios.get('users', {
               params: {type:'new'},
             }).then((response) => {
               this.new_users = response.data;
             }).catch((error) => {
               console.log(error);
             });
     }
},
mounted(){ 
 this.users();
 this.new_users();  

}

和我的 Django 视图中的 python 片段

def list_objects(request):
    if 'type' in request.GET and request.GET['type'] =='new' :
        #return new users
    else:
        #return users

问题是 new_users() 和 users() 方法响应新用户数据(最后调用的那个,如果我们最后调用 users() 方法,这两个方法都获取用户数据)

标签: pythondjangovue.js

解决方案


问题出在 Django 开发服务器上。当我切换到gunicorn时,所有问题都消失了,现在按预期工作。


推荐阅读