interaction between two django app

725 views
Skip to first unread message

Lorenzo Bernardi

unread,
Jan 24, 2017, 9:42:05 PM1/24/17
to Django users
Hello,

I don't know what is the best approach for the communication between
two django applications.

We have a website using django and django-cms. We have another
application, the "seminar" app for managing some informations like
seminars, news, people profiles.... They have both their databases and
are on different server. Now we would like to take some information from
the "seminar" appli and show them on the website. My question is how to
retrieve the data from the seminar app. We are developping both
applications so we can do whatever we want but for now we would like to
keep them separated. To display the information on the website I was
thinking of using template tags to gather the information and send them
to the page and I see 3 different ways to do access the information.

1) consider the distant database as a simple database and perform
queries in SQL.

2) use the models.py file of the seminar app (or use inspectdb) and
use database router to gather the information from the distant database
mode.

3) make a REST api of the seminar application ( I have no idea how
to do that and perhaps it is not the correct approach)

My main concern is that I'm in charge of the website part but not the
seminar part and this one may evolve without me knowing it and so I'd
like to be resilient to a change in the seminar app that doesn't modify
the fields I'm using. I mean the seminar app may have other models but
normally the seminar part should not change.

May be my question is not clear but I would like to know if other people
have this kind of setup one django app feeding another one and how did
they solve this problem.

sincerely.

L.

Daniele Procida

unread,
Jan 25, 2017, 10:28:11 AM1/25/17
to Django Users
On Tue, Jan 24, 2017, Lorenzo Bernardi <lorenzo....@lpn.cnrs.fr> wrote:

> I don't know what is the best approach for the communication between
>two django applications.
>
> We have a website using django and django-cms. We have another
>application, the "seminar" app for managing some informations like
>seminars, news, people profiles.... They have both their databases and
>are on different server. Now we would like to take some information from
>the "seminar" appli and show them on the website. My question is how to
>retrieve the data from the seminar app. We are developping both
>applications so we can do whatever we want but for now we would like to
>keep them separated. To display the information on the website I was
>thinking of using template tags to gather the information and send them
>to the page and I see 3 different ways to do access the information.

I think that given what you describe about the way the applications are being developed (by different teams, to meet different needs, which may evolve in different ways) that you are right to keep them loosely-coupled.

> 1) consider the distant database as a simple database and perform
>queries in SQL.
>
> 2) use the models.py file of the seminar app (or use inspectdb) and
>use database router to gather the information from the distant database
>mode.

Both these sound like bad ideas, given that you don't have control over the other database and application.

> 3) make a REST api of the seminar application ( I have no idea how
>to do that and perhaps it is not the correct approach)

This sounds by far the most sensible way to proceed.

You can't guarantee how the seminar application will contibue to be developed, or even if it will stay a Django application, but as long as the developer contibnue to provide a API that provides your application with the data it needs, you don't even need to care.

Now your only problem is to learn how to make REST APIs! But there is plenty of help available for that.

(If the two applications were to be run in the same project, and developed with a high degree of co-ordination, then you could consider using django CMS plugins to deliver Seminar information into other pages. But from what you describe, your best approach is to use them as REST clients for the information on the other system.)

Daniele

Bojan Nišević

unread,
Jan 25, 2017, 1:29:09 PM1/25/17
to Django users
Daniele Procida is completely right.

Just ask "the "seminar" app" team to provide you with a REST API and define which endpoints and responses on them you need. Django REST Framework will well fit into the seminar app. On your side you define views in which you make requests to seminar API endpoints and pickup responses parse them and forward them in get_context so you can use them in templates. Peace of cake.

They can change seminar app as much as they want. But, they need to maintain the REST API and document it for external users which in this case is you.
Reply all
Reply to author
Forward
0 new messages