【问题标题】:Django url based multi database基于 Django url 的多数据库
【发布时间】:2019-01-01 04:18:45
【问题描述】:

我需要将用户写入两个数据库。我决定将它们发送到不同的网址。 例如:/register/dbone//register/dbsecond/ 然后得到request.url 并将它们分开。 但是在路由器中,db_for_read()db_for_write() 两个函数对 request 对象和 url 一无所知。

如何最好地解决这个问题?这样做是因为数据的安全存储,所以第一个数据库中用户的初始存储是不可能的。

附:也许还有其他方法可以将用户分成两个数据库,不是 url 而是别的什么?

【问题讨论】:

标签: django database django-rest-framework


【解决方案1】:

我无法提供明确的答案,因为我看不到您的所有代码,但 django 文档显示 db_for_read()db_for_write() 实际上被称为:

db_for_read(model, **hints)db_for_write(model, **hints) 其中hints 基本上是kwargs where,引用django:hints received by the database router can be used to decide which database should receive a given request.

您需要将请求对象(或其他决定数据库的任何数据)中的任何数据传递到这些提示中。

【讨论】:

    猜你喜欢
    • 2016-11-06
    • 2019-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-23
    • 2021-07-13
    相关资源
    最近更新 更多