Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
375 views
in Technique[技术] by (71.8m points)

python - 将数据从Django应用程序发送到另一个Python脚本(Sending data from Django application to another Python script)

I have a Django application where some data can be saved on my database using a form.

(我有一个Django应用程序,可以使用某种形式在数据库中保存一些数据。)

I would like to create a Python script that, as soon as a new record is created, sends that data to an external Python script as json, and this external Python script should perform some operation with this data.

(我想创建一个Python脚本,一旦创建了一条新记录,它就会将该数据作为json发送到外部Python脚本,并且此外部Python脚本应对此数据执行某些操作。)

This question is not about code, but i'm trying to be as specific as possible: is there a way to create a system that sends data to another system?

(这个问题与代码无关,但我正在尝试尽可能具体:是否可以创建将数据发送到另一个系统的系统?)

In this case the data i need to send is the records submitted from forms of my Django app to another Python script.

(在这种情况下,我需要发送的数据是从我的Django应用程序的表单提交到另一个Python脚本的记录。)

I'm supposing that the external script should be listening to some sort of URL, maybe?

(我想外部脚本应该监听某种URL,也许吗?)

How could i accomplish this?

(我怎么能做到这一点?)

Maybe with Webhooks?

(也许使用Webhooks?)

  ask by Jack022 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I would suggest following:

(我建议如下:)

Your separate application establishes only one very simnple interface, that your django application can use.

(您单独的应用程序仅建立一个非常简单的界面,您的Django应用程序可以使用该界面。)

The only purpose is to tell your application, that there is data ready to fetch.

(唯一的目的是告诉您的应用程序,已经准备好获取数据。)

You could implement this via a simple TCP or UDP socket or via one dedicated http request.

(您可以通过一个简单的TCP或UDP套接字或一个专用的HTTP请求来实现。)

It doesn't really matter.

(没关系。)

Whenever your application gets notified that there are things to do it will connect via dedicated django views to ask what data can be fetched and fetch the data.

(每当通知您的应用程序有事情要做时,它都会通过专用的django视图进行连接,以询问可以获取哪些数据并获取数据。)

you could use the django rest frame work.

(您可以使用Django Rest框架。)

The whole point.

(整点。)

A django server is intended to provide data and to allow uploading data.

(Django服务器旨在提供数据并允许上传数据。)

Let your special application use django viewa to fetch and process data.

(让您的特殊应用程序使用django viewa来获取和处理数据。)

Either your application polls periodically or if your app really has to react immediately implement one simple way, that allows django to notify your application.

(您的应用程序会定期轮询,或者如果您的应用程序确实必须立即做出反应,请实施一种简单的方法,该方法允许django通知您的应用程序。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...