简体   繁体   English

如何在 2 个 Django 独立项目之间进行通信?

[英]How to communicate between 2 Django separate projects?

I have two separate Django projects and want to locate them in 2 different servers.我有两个单独的 Django 项目,并希望将它们放置在 2 个不同的服务器中。 Is there a way to communicate with each other?有没有办法互相交流? In one projects I need to be able to upload a file and send it to second project for processing.在一个项目中,我需要能够上传文件并将其发送到第二个项目进行处理。

It's called service discovery.这称为服务发现。 read more about it here: https://microservices.io/patterns/server-side-discovery.html在此处阅读更多相关信息: https : //microservices.io/patterns/server-side-discovery.html

basically you can just use python request library :基本上你可以只使用python 请求库

import request

files = {'upload_file': open('file.txt','rb')}
values = {'DB': 'photcat', 'OUT': 'csv', 'SHORT': 'short'}

r = requests.post(url, files=files, data=values)

and the response from the other server can be for example json with urls to the files, or something...来自其他服务器的响应可以是例如带有文件 url 的 json 或其他东西...
check python requests file upload检查python请求文件上传

but be careful, you should send some hashes/keys or something so other people can't imitate the behavior and send you false data.但要小心,你应该发送一些散列/密钥或其他东西,这样其他人就不能模仿这种行为并向你发送虚假数据。 That ofc depends on what you need it for那 ofc 取决于你需要它做什么

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

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