繁体   English   中英

从其他文件而不是 views.py 表单 DRF 向用户发送响应

[英]Send the response to user from other file instead of views.py form DRF

我正在研究 DRF,其中我创建了多个 python 并将该文件导入 views.py 但是当我尝试从另一个文件向用户发送响应时它不起作用我理解背后的原因但是有什么办法从 view.py 以外的地方向用户发送响应。

view.py 结构

#restframework view and all
from concurrent.futures import ThreadPoolExecutor
import other as o
call FileView(APIView):
   #parseclass 
   def post(self,request):
       o.func(d)
       

其他.py

from rest_framework.response import Response
from rest_framework.status import status
from django.conf import setting

def func(d):
    return Response({"A":"OK"})

但响应不会到达用户端。

有没有办法从 other.py 向用户发送响应,而不是获取价值,然后从 view.py 发送响应?

我还在我的 DRF 中实现多线程。

只需添加 return ,它应该可以工作:

class FileView(APIView):
    #parseclass 
    def post(self,request):
        return o.func(d)

如果你想跳过这一步,直接在 others.py 中调用 view。 只需将其设为 APIView 并在 urls.py 中注册即可。 它应该工作

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM