我認爲最簡單的解決方案將是:
django muliple databases +可以說,PostgreSQL的DB允許跨域訪問。
爲您的博客應用程序創建路由器並使用任何你想要的分貝。
UPD:
某處
# class for routing db operations for some blog myapp
class MyAppRouter(object):
"""A router to control all database operations on models in
the myapp application"""
def db_for_read(self, model, **hints):
"Point all operations on myapp models to 'other'"
if model._meta.app_label == 'myapp':
return 'other'
return None
def db_for_write(self, model, **hints):
"Point all operations on myapp models to 'other'"
if model._meta.app_label == 'myapp':
return 'other'
return None
def allow_relation(self, obj1, obj2, **hints):
"Allow any relation if a model in myapp is involved"
if obj1._meta.app_label == 'myapp' or obj2._meta.app_label == 'myapp':
return True
return None
def allow_syncdb(self, db, model):
"Make sure the myapp app only appears on the 'other' db"
if db == 'other':
return model._meta.app_label == 'myapp'
elif model._meta.app_label == 'myapp':
return False
return None
settings.py中
DATABASES = {
'default': {
...
# Project DB
}
# Blog DB
'blog': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'test',
'USER': 'postgres',
'PASSWORD': 'admin',
'HOST': '111.111.111.111',
'PORT': '5432',
}
}
...
DATABASE_ROUTERS = ['path.to.MyAppRouter', 'path.to.MasterSlaveRouter']
我不能說我明白你的問題。這聽起來像你有2個網站,一個將成爲「網站服務網站」。這有什麼問題?你是說博客將成爲你數據庫的門戶嗎?你只是想重新使用模型? – Nix
我想爲「n」個網站使用這個「博客」應用程序,所以我想把它作爲一項服務展示出來,任何第三方網站都可以使用它 –
唯一不同的是支持數據庫嗎? – Nix