简体   繁体   English

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

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

I am working on DRF in which I have created multiple pythons and importing that file into views.py but when I am trying to send the response to the user from another file it is not working I understand the behind the reason but is there any way to send the response to the user from other than view.py.我正在研究 DRF,其中我创建了多个 python 并将该文件导入 views.py 但是当我尝试从另一个文件向用户发送响应时它不起作用我理解背后的原因但是有什么办法从 view.py 以外的地方向用户发送响应。

view.py Structure 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)
       

Other.py其他.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"})

but Response is not coming to the user end.但响应不会到达用户端。

is there any way to send a response from other.py to the user instead of getting value and then send the response from the view.py?有没有办法从 other.py 向用户发送响应,而不是获取价值,然后从 view.py 发送响应?

I am also implementing multithreading in my DRF.我还在我的 DRF 中实现多线程。

Just add return and it should work:只需添加 return ,它应该可以工作:

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

If you want to skip this step and call view in others.py directly.如果你想跳过这一步,直接在 others.py 中调用 view。 Just make that an APIView and register it in urls.py.只需将其设为 APIView 并在 urls.py 中注册即可。 It should work它应该工作

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

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