Sapphire
Sapphire

Reputation: 1169

Can we combine two Django/python apps which connect to different databases into one integrated app

I have two standalone django apps that connect to different dbs. I want to make a parent app which routes the requests to one of the two child apps.

Is it possible and how can I achieve this? The parent app doesn't have to connect to any db, it should just route the requests to the child apps.

Thanks for the help.

Upvotes: 2

Views: 4921

Answers (1)

Marwan Alsabbagh
Marwan Alsabbagh

Reputation: 26828

This is possible. In Django think of apps as libraries that you can piece together and combine. So lets say you have the following:

  1. App A connects to db A
  2. App B connects to db B

You could just create one django project. Put both apps in your install apps INSTALLED_APPS. Check out the section on Multiple databases in the django docs. It will explain how to configure your apps so that they will automatically route to the correct database. Finally you don't really need to create a third parent app. Then edit your project's urls.py and define a route for each app. You can also call app A from App B, and redirect requests from one to the other as you need.

example urls.py

from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
    url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
    url(r'^admin/', include(admin.site.urls)),
)

The example above will route two separate apps to two different urls. Both these apps django.contrib.admindocs and django.contrib.admin ship with Django. The example is taken from the 2nd part of the Django tutorial.

Upvotes: 7

Related Questions